Difference between [ and [[ in if statements [duplicate]

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
This question already has an answer here:
What is the difference between [[ $a == z* ]] and [ $a == z* ]?
3 answers
Why does parameter expansion with spaces without quotes work inside double brackets â[[â but not inside single brackets â[â?
4 answers
The following code
if [ $a == "apple" ];
then
echo "True"
else
echo "False"
fi
outputs "True" ("False") if a="apple" (a="plum"). The comparison fails if one uses wildcards:
if [ $a == "appl"* ];
and is fixed if one replaces [ by [[:
if [[ $a == "appl"* ]];
What is the difference between [ and [[ in if statements?
shell-script
marked as duplicate by don_crissti, ilkkachu, Community⦠Dec 23 '17 at 16:11
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
This question already has an answer here:
What is the difference between [[ $a == z* ]] and [ $a == z* ]?
3 answers
Why does parameter expansion with spaces without quotes work inside double brackets â[[â but not inside single brackets â[â?
4 answers
The following code
if [ $a == "apple" ];
then
echo "True"
else
echo "False"
fi
outputs "True" ("False") if a="apple" (a="plum"). The comparison fails if one uses wildcards:
if [ $a == "appl"* ];
and is fixed if one replaces [ by [[:
if [[ $a == "appl"* ]];
What is the difference between [ and [[ in if statements?
shell-script
marked as duplicate by don_crissti, ilkkachu, Community⦠Dec 23 '17 at 16:11
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
What is the difference between [[ $a == z* ]] and [ $a == z* ]?
3 answers
Why does parameter expansion with spaces without quotes work inside double brackets â[[â but not inside single brackets â[â?
4 answers
The following code
if [ $a == "apple" ];
then
echo "True"
else
echo "False"
fi
outputs "True" ("False") if a="apple" (a="plum"). The comparison fails if one uses wildcards:
if [ $a == "appl"* ];
and is fixed if one replaces [ by [[:
if [[ $a == "appl"* ]];
What is the difference between [ and [[ in if statements?
shell-script
This question already has an answer here:
What is the difference between [[ $a == z* ]] and [ $a == z* ]?
3 answers
Why does parameter expansion with spaces without quotes work inside double brackets â[[â but not inside single brackets â[â?
4 answers
The following code
if [ $a == "apple" ];
then
echo "True"
else
echo "False"
fi
outputs "True" ("False") if a="apple" (a="plum"). The comparison fails if one uses wildcards:
if [ $a == "appl"* ];
and is fixed if one replaces [ by [[:
if [[ $a == "appl"* ]];
What is the difference between [ and [[ in if statements?
This question already has an answer here:
What is the difference between [[ $a == z* ]] and [ $a == z* ]?
3 answers
Why does parameter expansion with spaces without quotes work inside double brackets â[[â but not inside single brackets â[â?
4 answers
shell-script
asked Dec 23 '17 at 15:52
Viesturs
224138
224138
marked as duplicate by don_crissti, ilkkachu, Community⦠Dec 23 '17 at 16:11
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by don_crissti, ilkkachu, Community⦠Dec 23 '17 at 16:11
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
[is a command (basically a variant of thetestcommand).[[is a builtin in many shells.- When you write
foo*inside[...]filename expansion (aka globbing) occurs; while inside[[...]]pattern matching occurs. [[is more powerful and capable than[but should not be used if portability is a concern.[and[[are not part of theifsyntax, you can use them as in[ "$exit" = 'yes' ] && exit.- Inside
[...]you should prefer=instead of==. As far as I know, the second one is accepted in many shells but is not POSIX-compliant.
By the way, I recommend you to double-quote your variables even if you really know how word splitting will behave.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
[is a command (basically a variant of thetestcommand).[[is a builtin in many shells.- When you write
foo*inside[...]filename expansion (aka globbing) occurs; while inside[[...]]pattern matching occurs. [[is more powerful and capable than[but should not be used if portability is a concern.[and[[are not part of theifsyntax, you can use them as in[ "$exit" = 'yes' ] && exit.- Inside
[...]you should prefer=instead of==. As far as I know, the second one is accepted in many shells but is not POSIX-compliant.
By the way, I recommend you to double-quote your variables even if you really know how word splitting will behave.
add a comment |Â
up vote
2
down vote
accepted
[is a command (basically a variant of thetestcommand).[[is a builtin in many shells.- When you write
foo*inside[...]filename expansion (aka globbing) occurs; while inside[[...]]pattern matching occurs. [[is more powerful and capable than[but should not be used if portability is a concern.[and[[are not part of theifsyntax, you can use them as in[ "$exit" = 'yes' ] && exit.- Inside
[...]you should prefer=instead of==. As far as I know, the second one is accepted in many shells but is not POSIX-compliant.
By the way, I recommend you to double-quote your variables even if you really know how word splitting will behave.
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
[is a command (basically a variant of thetestcommand).[[is a builtin in many shells.- When you write
foo*inside[...]filename expansion (aka globbing) occurs; while inside[[...]]pattern matching occurs. [[is more powerful and capable than[but should not be used if portability is a concern.[and[[are not part of theifsyntax, you can use them as in[ "$exit" = 'yes' ] && exit.- Inside
[...]you should prefer=instead of==. As far as I know, the second one is accepted in many shells but is not POSIX-compliant.
By the way, I recommend you to double-quote your variables even if you really know how word splitting will behave.
[is a command (basically a variant of thetestcommand).[[is a builtin in many shells.- When you write
foo*inside[...]filename expansion (aka globbing) occurs; while inside[[...]]pattern matching occurs. [[is more powerful and capable than[but should not be used if portability is a concern.[and[[are not part of theifsyntax, you can use them as in[ "$exit" = 'yes' ] && exit.- Inside
[...]you should prefer=instead of==. As far as I know, the second one is accepted in many shells but is not POSIX-compliant.
By the way, I recommend you to double-quote your variables even if you really know how word splitting will behave.
edited Dec 23 '17 at 16:28
answered Dec 23 '17 at 16:10
nxnev
2,4622423
2,4622423
add a comment |Â
add a comment |Â