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

in Categories Decision Making last updated April 5, 2008


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. read n
    n2=expr $n % 2
    if [ $n2 -eq 0 ];
    then
    echo “even”
    else
    echo “odd”
    fi

  3. 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

    Have a question? Post it on our forum!