linux poison RSS
linux poison Email

Bash Script: Check if variable is integer or not

Below is a simple bash script to check if any given number is integer or not ...

#!/bin/bash
echo "Enter the value: ";
read num;
checkInteger(){
        if [ $1 -eq $1 2> /dev/null ]; then
                echo "$1 is a integer"
        else
                echo "$1 is not a integer"
        fi
}
checkInteger $num



1 comments:

Anonymous said...

Hi

You are simply checking if the value entered is equal to itself??? :)

Still, it's an awesome tip. Thanks!

Post a Comment

Related Posts with Thumbnails