On Fri, 01 Sep 2017 18:53:13 -0400, Eli Schwartz wrote:
Don't use error-prone logic e.g. foo=true; if $foo ...
Hey, I'm not to blame for this one :-)
This invokes an extra process as opposed to a simple value comparison,
That's not quite true: $ type true true is a shell builtin $ type false false is a shell builtin Bash won't actually make any syscalls when executing these commands in a conditional. Apparently the code paths within Bash are slightly faster for `[[ $v = true ]]` than for `$v`, but that's negligible compared to if it actually had to invoke an extra process as you said. Time for 1 million iterations: "v=true; if $v; then ..." | 7.1 sec "v=true; if [[ $v = true ]]; then ..." | 6.5 sec "v=/bin/true; if $v; then ..." | > 5 minutes (I got bored and killed it)
in the process of completely failing to act as expected when the variable is unset because of unrelated bugs.
And that's the real reason that this change should be applied. :-) -- Happy hacking, ~ Luke Shumaker