Shell

How to fix "unary operator expected error" in bash script

bash If testing a shell script produces an error like this:

[: =: unary operator expected error

Check the if condition on the reported line to see whether the variable has a value and whether the code uses [ $Ans = “Y” ]. If so, try changing it to:

[[ $Ans = "y" ]]

* With [[, you do not need to worry about whether the variable has a value. Or:

[ "$Ans" = "y" ]
EOF.← Back to articles