bash:shellcheck
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
bash:shellcheck [2016/10/17 14:21] – created peter | bash:shellcheck [2020/07/15 09:30] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
[[https:// | [[https:// | ||
Line 13: | Line 13: | ||
rm -rf " | rm -rf " | ||
</ | </ | ||
+ | |||
+ | ---- | ||
===== More Bad Code Examples ===== | ===== More Bad Code Examples ===== | ||
- | ===== Common beginner' | + | ==== Common beginner' |
+ | |||
+ | ShellCheck recognizes many common beginner' | ||
<code bash> | <code bash> | ||
+ | var = 42 # Spaces around = in assignments. | ||
+ | $foo=42 | ||
+ | for $var in *; do ... # $ in for loop variables. | ||
+ | var$n=" | ||
+ | echo ${var$n} | ||
+ | var=(1, 2, 3) # Comma separated arrays. | ||
</ | </ | ||
- | ===== Shell bad code ===== | + | ---- |
+ | |||
+ | ==== Style ==== | ||
+ | |||
+ | ShellCheck can make recommendations to improve style: | ||
+ | |||
+ | <code bash> | ||
+ | [[ -z $(find /tmp | grep msg) ]] # Use grep -q instead. | ||
+ | a >> log; b >> log; c >> log; # Use a redirection block instead. | ||
+ | cat file | grep foo # Useless use of cat. | ||
+ | </ | ||
+ | |||
ShellCheck is very easy to install and use. It is built and packaged using Cabal. We can install by apt-get/ | ShellCheck is very easy to install and use. It is built and packaged using Cabal. We can install by apt-get/ | ||
Line 53: | Line 75: | ||
| | ||
It is recommended to enforce a daily Shell Code Check! | It is recommended to enforce a daily Shell Code Check! | ||
+ |
bash/shellcheck.1476714104.txt.gz · Last modified: 2020/07/15 09:30 (external edit)