hashbang / hashbang.sh

Public facing website on hashbang.sh with embedded user creation script.
http://hashbang.sh
MIT License
141 stars 22 forks source link

`[ $?` anti-pattern #89

Closed lahemi closed 8 years ago

lahemi commented 8 years ago

cmd; if [ $? -eq 0 ] and cmd; if [ $? -ne 0 ] are redundant, as you are checking the return value of [.

if expects a command, meaning you can do if cmd; ...; fi.

KellerFuchs commented 8 years ago

@lahemi Thanks. If you don't mind, I will first patch the linter we use to detect this anti-pattern, because the best fixes are fixes where you make sure you don't make the same error again ;-)

lahemi commented 8 years ago

Sure, that's obviously a better way to approach this : )

KellerFuchs commented 8 years ago

See https://github.com/koalaman/shellcheck/issues/726 for the associated ShellCheck issue. Turns out that this is much trickier than expected.