4 ms·
shellcheck can remind you of most pitfalls
by jks 3y ago
shellcheck can remind you of most pitfalls
- hoherd 3y agoEvery time one of these "shell sucks" articles is posted I read the examples and think "shellcheck would catch that". Shellcheck is the main reason I have not migrated to zsh, or more generally it's because zsh doesn't have a syntax linter. More and more I find that confidence is one of the best goals you can have in every software and system project, and any tool or process that can increase your confidence is going to make your life easier. Shellcheck gives you that confidence when working with the shell. Never write shell code without it.
- arp242 3y agoIt should be said that many of the worst footguns shellcheck warns about simply don't apply to zsh – you don't need shellcheck to the same degree that you do with POSIX sh or bash. The first "wrong" example in this article for example (cp $i /tmp) is perfectly fine in zsh, and the complex 'mv "$i" "$(suf "$i")".jpg' is just 'mv $i $i:r.jpg' in zsh. $* and $@ are identical in zsh, and both are also arrays. There is no way to use it wrong really, and no weird '"$@" with quotes is a special case that's handled different from everything else'. Most "shell problems" people experience are "bash problems" (or "POSIX sh problems", but for many they're more or less synonymous); certainly pretty much all the problems listed in this article are. This always proves to be a controversial opinion, but I will forever keep insisting: just don't use POSIX sh or bash if it can at all be helped. You most likely don't need the portability, and installing zsh (or fish, or oil, or whatever) is easy enough in most the cases because you're the one controlling the environment.
- wpm 3y agoThat’s why it’s called bash: you gotta bash your head against the desk real hard sometimes before the damn thing does what you want.
- deleted 3y ago[deleted]
- ape4 3y agoYes but you get messy code
- Smaug123 3y agoTurns out that you get at most one of "readable" and "correct" with shell scripts!