Odd Even in Bash/Shell Scripting

I tried it so many times but it didn’t gave the solution but the code I have found on the net and I understood where my problem was

echo -n "Enter numnber : "
read number
 
remainder=$(( $number % 2 ))
 
if [ $remainder = 0 ]
then
  echo "$number is even number"
else
  echo "$number is odd number"
fi

caution: Don’t forget to give space after if eg. if [ ] and symbols eg. [ $remainder = 0 ]

and don’t forget to style after then eg.

then
echo “$number is evern”
else
echo “$number is odd”

if you don’t do all of the above mentioned system will give various errors.

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *