by dozzie · 9y ago · 0 comments
[ -z "$var" ]
This has literally no possibility of failing in any weird way, no matter which
Bourne or Korn shell descendant you use.you can even go further to do "${bar}", this is even safer I feel.
[ -z "${var-}" ]
works with +u or -uMost of the time, whatever is in [[ ]] can be easily emulated with POSIX/SUS-compatible tools and most of the time it doesn't matter that the tool is not a shell built-in.
Let's take people's favourite =~ operator. In bash, according to documentation, it uses ERE syntax. In zsh, it is ERE or PCRE, depending on an option being set. This is a subtle but important difference in how [[ ]] works. And then again, your environment can change the behaviour of a script you're running, which is (a) unexpected and (b) undesirable, and the change in the behaviour can range from "doesn't find thing it should" to "crashes" to "goes awry in an unexpected way".