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
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:
Hi
You are simply checking if the value entered is equal to itself??? :)
Still, it's an awesome tip. Thanks!
Post a Comment