top of page

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 ;;
esac

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.


Related Posts

Heading 2

Add paragraph text. Click “Edit Text” to customize this theme across your site. You can update and reuse text themes.

bottom of page