top of page

Shell Script Simple Quiz

Linux shell script allows the user to check for the answer until the correct answer given by the user. We are using the While loop to achieve it. The while loop enables you to execute a set of commands repeatedly until some condition occurs.


vi simple_quiz.sh
# !/bin/bash

echo What is the National Animal of INDIA
read ans
while test $ans != tiger
do
echo No, that\'s not it. Try again.
read ans
done
echo That is correct.

Here is the sample output of the above script

shell script simple quiz

More ways to use this while loop.

  • You can use while loop will print welcome 5 times on screen: x=1; while [ $x -le 5 ]; do echo "Welcome $x times" $(( x++ )); done

  • You can also use it while as infinite loops: while :; do echo 'Press <CTRL+C> to exit.'; sleep 1; done


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