Reputation: 6391
I'm trying to run a very simple script that reads input from a user and continuously loop a question if the users input doesn't match what is expected.
It's being execute via bash:
echo "Specify a directory [Y/N]?"
read ans
while [ [ "$ans" != "Y" ] || [ "$ans" != "y" ] || [ "$ans" != "N" ] || [ "$ans" != "n" ] ]
do
echo "$ans is not valid, please answer [Y/N]"
read ans
done
code continues....
Any idea why this is not working? It seems like a pretty straight forward loop.
Upvotes: 0
Views: 3784
Reputation: 2101
That should work:
echo "Specify a directory [Y/N]?"
read ans
while [ "$ans" != "Y" ] && [ "$ans" != "y" ] && [ "$ans" != "N" ] && [ "$ans" != "n" ]
do
echo "$ans is not valid, please answer [Y/N]"
read ans
done
There were a few mistakes:
[ ]
for a multiconditionnal while loopUpvotes: 1