0

I have a problem with this while loop. I want the user to pick one of the three options. I get the error "integer expression expected". When i remove the last option "$UCHOICE" -ne "q", the program works until i type a letter, and i get the same "integer expression expected". I am guessing that the problem has to do with integers and strings but i have no clue. please help.

while [ "$UCHOICE" -ne "1" -a "$UCHOICE" -ne "2" -a "$UCHOICE" -ne "q" ]
do
echo "hello"
read UCHOICE
done

2 Answers 2

3

You need to be using != for string comparison.

while [ "$UCHOICE" != "1" -a "$UCHOICE" != "2" -a "$UCHOICE" != "q" ]
do
echo "hello"
read UCHOICE
done
Sign up to request clarification or add additional context in comments.

Comments

1

I think the following message will help you:

stringA != stringB stringA does not match stringB

exprA -ne exprB Arithmetic expressions exprA and exprB are not equal

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.