I'm trying to prompt the user to enter, say either "5" or "10" And then store it as a variable. And if they do not enter either of these two numbers, to keep prompting them until they do. I've tried to run the following code, but it doesn't seem to work.

read -p 'Please enter your number. (5 or 10) ' num_choice

while (( $num_choice != 5|10))


read 'Please enter \"5\" or \"10\"' num_choice


echo "You've chosen the number $num_choice"

Also, it seems like the block quotes don't allow me to use single spacing, nor indent I'm assuming I'm doing something wrong. I apologize, I'm rather new to scripting! Thank you!

1 Answer 1


You can't use 5|10 on the right hand side of a comparator. You have to "distribute" the comparison

while (( num_choice != 5 && num_choice != 10 )) ; do
    read -p 'Please enter your number (5 or 10)' num_choice
echo "You've chosen $num_choice"

Note that you can still get errors if the user specifies a non-numeric string.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.