Bash Bracket Cheat Sheet (By Julia Evans)
wizardzines.com
wizardzines.com
[ Is a Builtin, But [[ Is Part of the Language
http://www.oilshell.org/blog/2016/10/12.html
There are lots of subtleties about it, which I don't really recommend learning. Oil fixes a bunch of these problems:
http://www.oilshell.org/blog/2020/01/simplest-explanation.ht...
But if you really want to know:
* It also has == which does NOT mean equality. It means fnmatch (glob) the right-hand side.
* Similarly, it has =~ to match a regex on the RHS. However you should avoid using a literal regex, and use a var $pat instead, because bash's lexing/escaping/quoting of the pattern is busted, and it even says so in the bash manual.
Summary:
[ "$a" == "$b" ] # string equality
[ "$a" = "$b" ] # string equality
[[ $a == $b ]] # fnmatch
[[ $a = $b ]] # fnmatch
[[ $a =~ $b ]] # regex match
[[ $a -eq $b ]] # numeric equality
(( a == b )) # numeric equality
(( a = b )) # numeric assignment!
Again, if you don't want to remember all that, try Oil instead :) Tell me what happens -- it's still open to feedback and change.It has dynamic types and operators like Python or JS. There's only one expression language, which replaces all these inconsistent constructs.
In other words, could a competent engineer write shell scripts well yet not have encountered that specific feature?