I cannot find the difference between:
[ $foo = b* ]
[ $foo == b* ]
[[ $foo = b* ]]
[[ $foo == b* ]]
I cannot find the difference between:
[ $foo = b* ]
[ $foo == b* ]
[[ $foo = b* ]]
[[ $foo == b* ]]
[]
vs [[ ]]
in general was covered at Is [[ ]] preferable over [ ] in bash scripts? so let's not touch it.
=
vs ==
:
Inside [ ]
=
is POSIX and checks if strings are equal==
is a Bash defined alias to it, see man bash
.So only use =
as it is both more portable and shorter.
Inside [[ ]]
[[ ]]
is not POSIX, so we refer only to man bash
.
It says under CONDITIONAL EXPRESSIONS
that =
and ==
are the same inside [[ ]]
and that both do pattern matching as described at "Compound Commands".
Then "Compound Commands" is the same pattern used for glob expansion, e.g.:
[[ 'abcde' = ?b[cC]* ]] && echo true
possibly with extglob
extensions.
Note that you must not quote the pattern: it will not glob expand to files as usual. If you quote it, you lose the pattern matching magic and get literal characters.
Difference between []
and [[]]
check this
Difference between =
and ==
=
is assignment operator
==
equality check operator OR conditional operator