Bad Advice
shellcheck doesn't always give the best advice. Here are some examples where you should ignore what shellcheck is saying.
Using printf with dynamic formats:
It is not always a mistake to use a variable in the format argument of printf. This should be ignored if you are using a dynamic format string.
Using parameter expansion inside the argument space of the :
built-in:
This should be ignored because shellcheck isn't smart enough to understand that the expansion of the variable is ignored because it appears in the argument space of the :
built-in. You do not need to add double-quotes as it suggests.
This same error pops up when you use a variable argument to the return
builtin. return only accepts an integer argument and thus it would be of little use to quote the variable when you know it will only ever be a number. The warning about word splitting does not apply in the below situation:
Rest assured, any instance of the following will suffer from the same bad advice:
Using sub-shells in the argument space of the export
built-in:
What shellcheck refers to as "return value" is actually the "exit status" of the sub-shell where uname -s
appears. If you don't care about the error, it should not matter that you put the sub-shell in the argument space of another command.
Using continue inside a loop when inside a function
Last updated