3 ms·
To spot more common problems I recommend: alias shellcheck='shellcheck -o all -e SC2292 -e SC2250'
by goombacloud 3y ago
To spot more common problems I recommend:
alias shellcheck='shellcheck -o all -e SC2292 -e SC2250'
- throw0101a 3y agoSC2292: Prefer [[ ]] over [ ] for tests in Bash/Ksh. * https://www.shellcheck.net/wiki/SC2292 https://www.shellcheck.net/wiki/SC2292 SC2250: Prefer putting braces around variable references (${my_var}) even when not strictly required. * https://www.shellcheck.net/wiki/SC2250 https://www.shellcheck.net/wiki/SC2250
- mgdlbp 3y agoOpportunistic interjection that unnecessary ${} is the most bothersome style choice in any language I know of: - It obscures actual uses of modifiers, particularly ${foo-} when set -u is in effect, - It's obvious when a name runs into subsequent text, even if one has somehow avoided syntax highlighting, - And expansions followed by identifier chars don't actually occur in practice. Cases where the quotes cannot be moved to surround the variable are often interpolation of an argument to echo, whose behaviour is such a mess not even portable between bash and dash that shellcheck ought to be demanding printf at all times instead!
- arp242 3y agoRelated pet peeve: always writing variables as $UPPER_CASE in shell scripts. Useful: $UPPER_CASE for exported variables ("super globals"), $lower_case for anything else. Can also use $lower_case for function locals and $UPPER_CASE for exported and script global variables (stylistic preference; both are reasonable). Not useful or reasonable: $ALWAYS_UPPER_CASE_NO_MATTER_WHAT. I suppose people started doing it because they saw $EXPORTED_VARIABLE and thought "oh, I need to always upper case it", not realizing what that meant. And then after that more copy-copy of this "style".