bash and arithmetic comparison: double quotes or not?
Posted
by
Martin
on Super User
See other posts from Super User
or by Martin
Published on 2012-11-29T10:28:40Z
Indexed on
2012/11/29
11:09 UTC
Read the original article
Hit count: 381
bash
|comparison
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 !
© Super User or respective owner