In: Computer Science
LINUX
In Linux command line write a shell script ex1.sh that uses IF THEN to
Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command)
If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember you want to use the Integer Operators like –lt.)
Run 'cat ex1.sh'
Run 'sh ex1.sh' and enter 3 when prompted
Run 'sh ex1.sh' and enter 5 when prompted
Run 'sh ex1.sh' and enter 7 when prompted
Shell Script: ex1.sh
#!/bin/bash
# Prompting user to enter a number
echo -n " Enter a number between 1 and 10: "
# Reading a number
read NUM
# If condition to check for number that is less than 5
if [ $NUM -lt 5 ]; then
echo "\n The number is less than 5 \n"
else
# Number entered is greater than 5
echo "\n The number is greater than or equal to
5 \n"
fi
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sample Output: