Saturday, May 12, 2012
1:00 AM

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

0 comments:

Post a Comment