I’m a noob to shell scripting and am wondering about this:
#!/usr/local/bin/bash
number=5
echo "Enter 'yes' to continue, 'no' to abort:"
read choice
if [ $choice = yes ]; then
while [ $number -lt 10 ]; do
echo "The script is now looping!"
done
elif [ $choice = no ]; then
echo "Loop aborted"
else
echo "Please say 'yes' or 'no'"
read choice
# What now?
fi
How would I go about the if statement rechecking your $choice (On line 13) if you do not specify “yes” or “no”?
Thank you.
You can put the code from “echo Enter…” till fi in an outer “while” loop. The while loop would loop until $choice is “yes” or “no”. Remove the last “else” clause while doing this (it would be redundant).
P.S. you need to increment (or change) $number in your inner while loop. Otherwise, it will run infinitely.