Why am I getting a ShellCheck error when sourcing a script?

0
4
Asked By CuriousCoder42 On

I'm trying to use ShellCheck for the first time and ran into an issue. When it checks a line in my script that sources another script, it throws an error. From what I've gathered in the ShellCheck documentation, I should be able to use a directive to define what my source path is, but it doesn't seem to be working. The lines in my script are:

SCRIPT_DIR=$(dirname "$0")
# shellcheck source-path=SCRIPTDIR
source "$SCRIPT_DIR/bash_env.sh"

But I'm getting this error:

In _setenv.sh line 45:
source "$SCRIPT_DIR/bash_env.sh"
^-----------------------^ SC1090: Can't follow non-constant source. Use a directive to specify location.

What could I be doing wrong? Thanks for any help!

1 Answer

Answered By ShellGuru88 On

It sounds like you're on an older version of ShellCheck. In versions up to 0.7.1, using `source "$variable/path.sh"` will give you errors because it can't figure out the path. You'd need to specify the filename with `# shellcheck source=myfile.sh`. But from v0.7.2 and on, if you set up `source-path`, it should link to `bash_env.sh` alongside your script. You might want to check for updates!

UpdateSeeker -

Thanks for the tip! I just updated but the highest version I can get via "sudo apt install" is still v.0.7.0. I think I'll check out the GitHub repository to get the latest.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.