Linux shell script allows you to present a multiple choice question and gets the user’s answer, and reports back whether the answer is right, wrong, or not one of the choices. Here we will user case to match the answer which we accept using the read command.
echo Shell script is
echo a\) an Operating System
echo b\) a media player
echo c\) a command-line interpreter
echo d\) all of the above
case $answer in
a) echo Wrong - the answer is c ;;
b) echo Wrong - the answer is c ;;
d) echo Wrong - the answer is c ;;
c) echo Right ;;
*) echo Not one of the choices ;;
Here is the sample output of the above script
More way to use this case command
You can use the case command to evaluate the argument.
You can also use it to return the output according to the user inputs.
Add paragraph text. Click “Edit Text” to customize this theme across your site. You can update and reuse text themes.