Shell script to read a number and find whether the number is odd or even

in Categories Decision Making last updated April 5, 2008
#!/bin/bash
# Shell script to read a number and find whether the number is odd or even
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
echo -n "Enter numnber : "
read n
 
rem=$(( $n % 2 ))
 
if [ $rem -eq 0 ]
then
  echo "$n is even number"
else
  echo "$n is odd number"
fi

Share this on:

15 comment

  1. echo “enter the number”
    read n

    2num=$(( $n % 2 ))
    if [ $num -eq 0 ]

    then
    echo “$n number is even”
    else
    echo “$n number is odd”
    fi

  2. echo “Program to check even or odd number”
    echo “Enter a number”
    read n
    a=`expr $n % 2`
    if [ $a -eq 0 ] ; then #Semicolon is most important for Executing if-else
    echo “It is an even number”
    else
    echo “It is an odd number”
    fi

Leave a Comment