Having the following for simplicity:
while
echo -n "Does the command include flag(s)? (Y/N): "
read option
echo "option: '${option}'"
# Is mandatory use `==` and NOT `-eq`
if [[ $option -eq "y" || $option -eq "n" || $option -eq "Y" || $option -eq "N" ]]; then
echo "Valid option"
break;
else
echo "Invalid option"
fi
do :; done
If an input of a number is applied it works how is expected: Invalid option appears, but when any character is used how input always Valid option appears and it is not correct, but if is used (observe now == is used and not -eq)
while
echo -n "Does the command include flag(s)? (Y/N): "
read option
echo "option: '${option}'"
# Is mandatory use `==` and NOT `-eq`
if [[ $option == "y" || $option == "n" || $option == "Y" || $option == "N" ]]; then
echo "Valid option"
break;
else
echo "Invalid option"
fi
do :; done
All work how is expected from the beginning.
So what is the difference between == and -eq in an if statement?