Shell Scripting-1(Even-Odd)
A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. We will be using Bash shell scripts here for various operations.
- Find whether the given number is Even or Odd
In the shell script below we will find if the input number is even or odd. Simple division formula is used here. If the number is divided by 2 and the reminder is 0, then the number is even. Else the number is odd.
Note: Be careful about spaces in Bash scripts. Extra space or not giving necessary space may result in error.
echo "Enter any Number:" read n if [ $(( $n % 2 )) == 0 ] then echo "Number is even" else echo "Number is odd" fi