SC1091 — Not following source file: fix in 30 seconds

Fix ShellCheck SC1091: ShellCheck cannot resolve your source path. How to silence it safely with a directive, without hiding real bugs.

Problem

SC1091 fires whenever ShellCheck encounters `source path/to/file` (or `. path/to/file`) and cannot resolve the target. The most common causes are dynamic paths (`source "$HOME/.config/foo"`), files that live outside the analyzed directory, and CI environments where the dependency isn't checked out. The risk isn't the sourced file — it's that ShellCheck can't lint the variables and functions it defines, so genuine bugs further down may go unreported.

Bad

#!/usr/bin/env bash
source ../shared/lib.sh   # ShellCheck: SC1091, can't follow

Good

#!/usr/bin/env bash
# shellcheck source=../shared/lib.sh
source ../shared/lib.sh

# Or, when the path is dynamic, point at a representative file:
# shellcheck source=src/lib/defaults.sh
source "$CONFIG_DIR/defaults.sh"

Explanation

The `# shellcheck source=` directive tells ShellCheck where to find the file relative to the current script. Use the real path when it is static; use a representative file when it is dynamic. Never blanket-disable SC1091 — you'll lose downstream type information.

Related

SC1090

When It Matters

ShellCheck found a literal path in a source line but could not open the file, so everything that file defines is unknown to the rest of the analysis. That usually means the path is relative to the runtime working directory rather than to the script, which is also a runtime bug waiting to happen: run the script from another directory and the source fails. So the warning frequently points at a real fragility, not just an analysis gap.

Second Example

Note

BASH_SOURCE[0] is the path of the file currently being read, which is correct inside sourced libraries too — unlike $0, which names the outermost script.

Exceptions

Sourcing a file that only exists at runtime — a generated environment file, /etc/os-release, a virtualenv activate script — cannot be resolved at check time. Use "# shellcheck source=/dev/null" for those and keep a real source= directive everywhere the file is in the repository.

Faq

Q

How do I point ShellCheck at the right file?

A

Put "# shellcheck source=path/to/file.sh" immediately above the source command, or set a search root with "# shellcheck source-path=SCRIPTDIR".

Q

Is source the same as . ?

A

The dot is POSIX; source is a Bash synonym. Both run the file in the current shell rather than a subprocess.

Q

Why does the script work locally but fail in CI?

A

Almost always a relative source path plus a different working directory. Anchor it to BASH_SOURCE and it works from anywhere.