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

Shell Script to find Number is Even or Odd

GET ALERTS:

Get our Latest updates delivered to your mailbox!

This is a basic shell script to find whether given number is even or odd. Here we use a simple condition rem=$(( $n % 2 )) to check the number is even or not. If the remainder is 0 then the number is Even else it is odd.

echo "Enter a Number:"
read n

rem=$(( $n % 2 ))

if [ $rem -eq 0 ]
then
	echo "Number is even"
else
	echo "Number is odd"
fi

Output:
even

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: