Pages

Wednesday, April 2, 2014

Bash shell Script to find even odd number

How to find whether number is even or odd.Below is the bash shell script example

#!/bin/bash
#Developed & Written by Krunal Patel
#Email:bashshellexpert@gmail.com
#Copyright Krunal Patel
read -p "Enter the number that you want to check for even or odd : " check_num
case $check_num in
     [a-z]* | [A-Z]*)
echo "You typed the letter $check_num\nIt is invalid integer number\nPLease Enter Digit\nExiting the program..."
exit
         ;;


     [0-9]*)
if [ $(($check_num % 2)) -eq 0 ];
then
echo "Number you have entered is '$check_num' and it is even"
else
echo "Number You have entered is '$check_num' and it is odd"
fi
         ;;

      *) echo "You did not type a letter or a digit\nPlease enter valid interger number\nExiting the program...\n"
exit
   ;;
esac


To Download script click here

Shell Script Code