home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Check If A Number Is Even Or Odd In Bash Shell Scripts

May 2023
Code
NUMBER=10

if [ $(($NUMBER%2)) -eq 0 ]
then
  echo "even"
else
  echo "odd"
fi

To check for just and odd number, use:

Code
NUMBER=9

if [ $(($NUMBER%2)) -ne 0 ]
then
  echo "odd"
fi
═══ § ═══