What is the best practice to source a local bash file? I get the following shellcheck error on my bash script as it can't follow the path provided in the source:
Code snippet that gives the formatting error:
source ../<local-bash-file>.sh
Shellcheck error:
SC1091: Not following: ../<local-bash-file>.sh was not specified as input (see shellcheck -x).
It is important to note that the build trigger that gives this error doesn't use the shellcheck -x. How should I reformat my source line to pass this check?
Tried adding absolute and relative path
The shellcheck wiki has more information on all shellcheck messages.
You have a few options:
Tell shellcheck to follow all
sources in your code. In your case, you need to modify how you call shellcheck and pass the-xflag. This is probably the easiest way and will work for all shellcheck calls in your build.Specify
external-sources=truein your shellcheck configuration file, if you use one. This may be the preferred way when running shellcheck locally, but in a CI environment you may want to be more explicit with the-xflag above.Hard-code the file name you source, by adding
# shellcheck source=somefileon the line above thesource. Make sure you pass the same file name. This requires touching allsources (and. somefile.sh) lines and may be a bit labor intensive, but you're very explicit about what gets checked, and it's the most fine-grained approach (in case you care about this).Suppress the warnings, one at a time: Add
# shellcheck disable=SC1091on the line before thesource. I'd try to avoid this, as the sourced code won't get checked here. It may be necessary to silence this when you dynamically build the file name of the file you want to source.Suppress the warning everywhere: call
shellcheckwith-e SC1091toexclude the given warning. This doesn't rely on the configuration file, but you may have to add it to multiple shellcheck calls.