lundi 7 mai 2018

Bash script: While loop with If statement results in infinite loop

I'm trying to write a bash script that asks if a person wants a cup of tea, with Y returning “Great, I’ll make tea now” to the console"; and N returning “Are you sure” 4 more times before stopping the loop. Also if during the 4 follow up offers, the user changes their mind and presses ‘Y’, the computer will print out “Great, I’ll make tea now” to the console.

My script below results in an infinite loop, so I need some increment count in the code and I just cant figure out where? Possibly a very basic question and if so apologies, new to Linux Bash scripting, any help appreciated:

#!/bin/bash
#tea2.sh
echo Will you have a cup of tea?
read answer
while [ $answer = n ]
do
  echo Are you sure           
  if [ $answer = y ]
  then
        break              
  fi
  echo Great, I\’ll make tea now         
done

Aucun commentaire:

Enregistrer un commentaire