if [ "$FOO" = "true" ]; then
if [ $FOO = "true" ]; then
What is the different? Seems both of two statements also works.
This question came from our site for professional system and network administrators.
If the value of
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
Hope I've not confused you with these examples.
In this specific case there is no difference.
However, if $FOO contains a space or some special characters you will have a problem.
In the "$FOO" case, it will use the variable in total to make the match insulating you from the space problem.
However, if you use $FOO and there is a special case it will affect the if statement.