bash and arithmetic comparison: double quotes or not?
- by Martin
when comparing two integers in bash, do we have to put double quotes ?
In the official document http://tldp.org/LDP/abs/html/comparison-ops.html I can read that double quotes should appear every time... But what is the differences in the following examples:
[ "$VAR" -eq "1" ]
[ $VAR -eq "1" ]
[ "$VAR" -eq 1 ]
[ $VAR -eq 1 ]
As I am curious, a took a look at Ubuntu init scripts in /etc/init.d and there are many usage of arithmetic comparison in it, at least [ "$VAR" -eq "1" ] and [ $VAR -eq 1 ] are used... but it seems no one really "knows" what is the official way to do it.
Thanks !