I have a bash script, which, at one point asks the user for confirmation. I do this by reading a single character, which is then transformed to lower case and checked if it is 'y'. If not, the script exits.
Now, if I simply press enter on the input read, I get error: unary operator expected
. How can I prevent this issue or catch the error?
Code snippet:
echo -ne "Confirm [y/n]: "
read -n1 uc
if [ ${uc,,} != "y" ]
then
exit 0
fi