Answer to Question #207844 in UNIX/Linux Programming for hamza

Question #207844

Write a bash script to check whether the input number is EVEN, ODD or neither EVEN nor


1
Expert's answer
2021-06-19T07:00:40-0400
#!/bin/bash
# Reading the number
read -p "Enter a number: " number

# Checking whether the input is the number
if ! [[ "$number" =~ ^[0-9]+$ ]]
  then
    echo "Neither even nor odd."
  # Checking whether the number is even
elif [ $((number%2)) -eq 0 ]
  then
    echo "Number is even."
else
  echo "Number is odd."
fi

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS