Linux shell programming string compare syntax
In general, the = operator works the same as == when comparing strings.
Note:The == comparison operator behaves differently within a double-brackets test than within single brackets.
[[ $a == z* ]] # True if $a starts with an "z" (pattern matching).[[ $a == "z*" ]] # True if $a is equal to z* (literal matching).[ $a == z* ] # File globbing and word splitting take place.[ "$a" == "z*" ] # True if $a is equal to z* (literal matching).
These pages explain the various comparison operators in bash:
- http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/
- http://tldp.org/LDP/abs/html/comparison-ops.html
- http://www.faqs.org/docs/Linux-HOWTO/Bash-Prog-Intro-HOWTO.html#ss11.2
On the second linked page, you will find:
== is equal to if [ "$a" == "$b" ] This is a synonym for =.