Skip to content
Virgil edited this page May 8, 2019 · 9 revisions

Can't follow non-constant source. Use a directive to specify location.

Problematic code:

. "$(find_install_dir)/lib.sh"

Correct code:

# shellcheck source=src/lib.sh
. "$(find_install_dir)/lib.sh"

Rationale:

ShellCheck is not able to include sourced files from paths that are determined at runtime. The file will not be read, potentially resulting in warnings about unassigned variables and similar.

Use a Directive to point shellcheck to a fixed location it can read instead.

Exceptions:

If you don't care that ShellCheck is unable to account for the file, specify # shellcheck source=/dev/null.


⚠️ this section references functionality not yet in the stable release.

shellcheck -P SOURCEPATH, --source-path=SOURCEPATH

shellcheck -P dir1:dir2/libs

Specify paths to search for sourced files, separated by : on Unix and ; on Windows. Absolute paths will also be rooted in these.

The special path SCRIPTDIR can be used to specify searching the currently checked script's directory, as in -P SCRIPTDIR or -P SCRIPTDIR/../libs. Subsequent -P flags accumulate and take precedence.

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally