Using OR (-o) in while loop... HELP

Need to ask user question and get user to input YES or NO otherwise loop. Below is my code but its not working. Please help, I'm using bash shell.

echo "How about some YES or NO questions --- Are you ready ?"
echo "1. Do you own an iPhone ?"
read ANS1
while [  ["$ANS1" != "YES"] -o [$ANS1 != "NO"] ]
do
  echo "Please answer with YES or NO"
  read ANS1
done

Change

while [ ["$ANS1" != "YES"] -o [$ANS1 != "NO"] ]

to

while [[ ! $ANS1 == @(YES|NO) ]]
echo "How about some YES or NO questions --- Are you ready ?"
echo "1. Do you own an iPhone ?"
read ANS1

while(true)
do
        if [ "$ANS1" = "YES" ] || [ "$ANS1" = "NO" ]
        then
                print "$ANS1"
                break;
        else
                echo "Please answer with YES or NO"
                read ANS1
fi

done

Getting error: Syntax error: "(" unexpected (expecting "do")

Or:

echo "How about some YES or NO questions --- Are you ready ?"
echo "1. Do you own an iPhone ?"
read ANS1
while [ "$ANS1" != "YES" ] && [ "$ANS1" != "NO" ]
do
   echo "Please answer with YES or NO"
   read ANS1
done
1 Like

Getting this error:

Warning: unknown mime-type for "NO" -- using "application/octet-stream"
Error: no such file "NO"

---------- Post updated at 12:53 AM ---------- Previous update was at 12:48 AM ----------

Thanks works good. Kindly explain to me the condition. I thought for bash its meant to use -a instead of && ???

The condition is loop while ANS1 is not YES and ANS1 is not NO (or not YES or NO). There are many ways to test for the OR as shown on the other posts.

1 Like