When running the code below, I’d like to read a user-input answer until it is one of the 6 possible answers ([abcABC]), else continue with the next loop.
However, it does not exit the while loop when I enter one of the accepted answers.
I tried [] and [[]] for the conditions, I tried to place all of the conditions into one pair of square brackets, I tried to use | and ||, none of them worked as expected.
while [ "$ans" != "a" ] || [ "$ans" != "A" ] || [ "$ans" != "b" ] || \
[ "$ans" != "B" ] || [ "$ans" != "c" ] || [ "$ans" != "C" ]; do
read ans
case $ans in
[aA]) echo "aA" ;;
[bB]) echo "bB" ;;
[cC]) echo "cC" ;;
*) echo "Try again." ;;
esac
done
It should read in loop until one of the accepted answer is given; then it should continue with the following code (if any).