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
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!
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.