ShellCheck's -x Flag Lets You Source Files without SC1091 Warnings
This is really handy to avoid having to add a source path as a comment or ignore SC1091 every time you source a file.
I’m a really big fan of ShellCheck. Often
times your shell scripts might source in another file. When you call
shellcheck -x myscript
instead of shellcheck myscript
that lets ShellCheck
know to check the path of sourced files without explicitly annotating them with
a comment.
It will still detect source calls with incorrect paths too because it tests the
path by default when using -x
. If you don’t use -x
chances are you’ve found
yourself adding shellcheck specific comments like # shellcheck disable=SC1091
to every file you source.
# Demo Video
Timestamps
- 0:06 – Demonstrating the SC1091 warning and how to fix it
- 1:06 – Using the -x flag to avoid annotating every time you source a file
- 1:32 – I might alias shellcheck to always run with -x
- 2:07 – The -x flag still tests to make sure the sourced file exists
Reference Links
Will using -x make its way into all of your shellcheck commands? Let us know!