bash and arithmetic comparison: double quotes or not?
You need to quote $VAR
if it could possibly be empty/unset (so you should probably always quote it).
If you don't quote it and it's empty, the statement results in:
[ -eq 1 ]
which is a syntax error. Quoting the 1
doesn't gain anything though.
(Also look at bash conditional expressions (things with [[ ... ]]
), a more "modern" version of the test command that has less quirks.)
If you want to arithmetic comparison, use the arithmetic conditional construct (documented here):
(( VAR == 1 ))