shellcheck -s dash -e SC2004,SC2034,SC2166,SC2169 FILE
-e ...
argument is required to disable checks that are not accurate. Below is a discussion about each:SC2004
checks for $
/${}
applied to variable names inside arithmetic expressions inside $(( ... ))
:-e
to make shellcheck ignore this situation. Shell code in the FreeBSD base Operating System should use leading dollar signs to make code more portable.SC2034
checks for unused variables..
builtin. Also, do not simply export
the variable to get rid of this warning. If your program exports too much information, it may fail to fork external executables (by design). The Operating System commonly places limits on process resources for all users except the root
superuser and as-such, export
should be used sparingly and only when absolutely necessary to pass the variable to an external executable.SC2166
warns if you pass more than 4 arguments to the [
builtin or if you use the -a
or -o
options to the [
builtin:-a
and -o
options to the [
builtin to combine tests even if not strictly supported by POSIX. The number of shells that do not support this are rare.SC2169
warns about dash
short-comings but can become confused when you use dynamic file descriptor redirection:$stderr
resolves to a number to invoke the >&n
syntax for redirecting to a specific file descriptor. It is complaining here because it thinks you are trying to use a csh
feature which allows you to redirect both stdout and stderr to a file by using >& file
instead of > file
(which in any shell only redirects stdout into file).