bash script question

Linux for blind general discussion blinux-list at
Mon Dec 12 04:52:10 UTC 2022

First you have fi on the line right below do, but that fi seems to 
belong to your quiz function, so I moved it there. I also did not find 
done at the end of the do loop, so I have added that. Lastly the 
function was not closed, so I have added the closing curly bracket on a 
line by itself below the function. I also assume you want to actually 
exit the script if the response is not Y or y, so I add an exit after 
the echo. After these fixes, the script seems to work as expected, 
although I'm not sure you wanted to ask to start the quiz after an 
incorrect answer, but I left that as it was. I also separated the 
function from the main script by a blank line and fixed indentation, but 
this is just for readability, and your script will work as expected 
without these fixes. Find below the working script.


quiz() {
   echo "Starting quiz..."
   echo "What is 2+2?"
   read response
   if [ "$response" == 4 ]
     echo "You got it."
     echo "That is incorrect."

until [ "$response" == 4 ]; do
   echo "Begin math quiz? (y/n)"
   read response
   if [ "$response" == "y" ] || [ "$response" == "Y" ]
     echo "The quiz took you $SECONDS seconds to complete."
     echo "Exiting..."

More information about the Blinux-list mailing list