Written by Sai Sandeep Thota on April 18, 2013 in Programming > Shell

Shell Script to Check Number is Positive or not

GET ALERTS:

Get our Latest updates delivered to your mailbox!

How do you find a number is positive or negative. By checking if it is greater than zero or not. Here we use the same
condition for checking the Number if it is positive, negative or equal to zero.

echo "Enter a Number:"
read n
if [ $n -gt 0 ]
then 
	echo "Number is positive"
else
	if [ $n -eq 0 ]
	then
		echo "Number is Zero!"	
	else
		echo "Number is Negative!!"
	fi
fi

Output:
positive

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: