e.g.
if [ "$FOO" = "true" ]; then
vs
if [ $FOO = "true" ]; then
What is the different? Seems both of two statements also works.
e.g.
vs
What is the different? Seems both of two statements also works. |
||||
migrated from serverfault.com Aug 14 '13 at 22:09This question came from our site for system and network administrators. |
||||
If the value of If Incidentally, |
||||
|
To illustrate what problems it might cause, here a few examples. Let's say we have two variables as follow:
Now we have two variables holding exactly the same string/value. If we did some if statements to test the result, in your case:
At this point you will get When we quote "$FOO" we explicitly tell Another example:
Hope I've not confused you with these examples. |
||||
|
In this specific case there is no difference. However, if In the However, if you use |
||||
|
a='foo bar'; [[ $a == "foo bar" ]]
. However, a variable which does not contain glob characters need not be:[[ $a == $a ]]
. Word expansion is not performed inside double square brackets. And for regex matching, the pattern on the right hand side must not be quoted or it will be taken as literal string:[[ $a =~ .*oo.*r ]]
(the pattern should be in an un-quoted variable, however, instead ... – Dennis Williamson Aug 15 '13 at 1:14[[ $a == foo* ]]
. Can you provide any additional examples of a requirement for quoting besides my literal string example? – Dennis Williamson Aug 15 '13 at 1:14