Tuesday, 11 June 2013

Shell Script to accept a number and display whether the number is positive, negative or zero.

Code:
echo -n "Enter the Number : "
read x
if [ $x -lt 0 ]
then
        echo "$x is Negative"
elif [ $x -eq 0 ]
then
        echo "Number entered is Zero"
else   
        echo "$x is Positive"
fi


Output:
[ty2011330@localhost ~]$ sh j02.sh
Enter the Number : 7
7 is Positive
[ty2011330@localhost ~]$ sh j02.sh
Enter the Number : -9
-9 is Negative
[ty2011330@localhost ~]$ sh j02.sh
Enter the Number : 0
Number entered is Zero

No comments:

Post a Comment