Name the ShellCheck warnings you see most and what each means.
IntermediateConceptShellCheck, debugging, testing, portability and security
Answer
| Code | Meaning |
|---|---|
| SC2086 | Double quote to prevent globbing and word splitting |
| SC2046 | Quote this to prevent word splitting (unquoted $(...)) |
| SC2155 | Declare and assign separately to avoid masking return values |
| SC2164 | Use cd ... || exit in case cd fails |
| SC2034 | Variable appears unused |
| SC2181 | Check exit code directly with if mycmd;, not $? |
| SC2068 | Double quote array expansions to avoid re-splitting elements |
| SC2207 | Prefer mapfile or read -a to split command output |
| SC1091 | Not following a sourced file (use -x or a source= directive) |
| SC2016 | Expressions don't expand in single quotes |
More on ShellCheck, debugging, testing, portability and security
What is ShellCheck and how do you use it in a team?BeginnerHow do you disable a ShellCheck warning, and when is that acceptable?IntermediateHow do you debug a Bash script?BeginnerHow do you make `set -x` output more useful with `PS4`?IntermediateWhat is bats, and how do you test a script that calls external commands?IntermediateWhat is `shfmt` and why use it alongside ShellCheck?Beginner