• Arun Kumar

Shell Script for Multiple Choice Questions

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.

vi multi_choice_question.sh
# !/bin/bash

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
read answer
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

shell script for multiple choice questions

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.


Recent Posts

See All