I tried many different combinations with brakets, quotation marks, ||
, -o
, but the only way the script works without infinit loop is without the OR in while loop comparison, like this: while [ $name != Jorge ]] ; do ...
This is an example of an script that I want to run:
#!/bin/bash
echo "What is my name: "
read name
while [ $name != "Jorge" ] || [ $name != "Eduardo" ] ; do
echo "Not. Try again: "
read name
done
echo "Well done!"
You should use &&
instead of ||
in the condition of while statement.
You are trying to read a name from stdin and if that name is "Jorge" or "Eduardo", you are done. when putting it in condition of while, you want to continue in the loop when the name if not "Jorge" and the name is not "Eduardo".
your current condition says that continue in the loop if the name is not "Jorge" or the name is not "Eduardo". And the name cannot be both at the same time.