4 ms·
Do yourself a favor and read the linked section. The "elegant" method sure can be nice, but comes with a downside you really need to be aware of. I love shell
by mr-wendel 6y ago
Do yourself a favor and read the linked section. The "elegant" method sure can be nice, but comes with a downside you really need to be aware of.
I love shell scripting and this highlights one of the major problems with bash: small changes like this can appear completely interchangeable with other mechanisms for doing the same thing but introduce edge cases that can unexpectedly bite you.
For example... consider what happens if "[ $foo -eq 0 ] && /bin/do-something" is the last statement within a function or the end of your script.
- e40 6y agoI came here to make this comment. It really needs to be a top-level comment and at the top. I have wasted many hours of my life tracking down buts where the idiom in the OP was used in a function. It leads to really hard to find bugs. Beware!!!