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

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.


7 views

Recent Posts

See All

Basic Linux Commands

This article describes basic Linux commands that you must know as a system or database administrator. Below commands in Linux help you manage any Linux server fast and smoothly. Linux Command List Che

Linux Firewall with iptables and firewalld

In this article will be covering details regarding iptables and firewalld which helps in Linux firewall management. We will also be looking at how to enable specific ports (1521 for Oracle) inside ipt

Passwordless SSH in Linux

Every time you ssh from one Linux server to another, you need to enter target server user's password. We can also setup passwordless ssh in Linux between two Linux servers so that you don't have to en

  • Facebook
  • Twitter
  • YouTube
  • Instagram

© 2020 by DBA Genesis