From e8cb74cc185d80bae6ec5a736e90aac55bdf8215 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 18 Sep 2021 18:37:51 -0700 Subject: [PATCH] Updated Directive (markdown) --- Directive.md | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/Directive.md b/Directive.md index d8910d0..b58edd5 100644 --- a/Directive.md +++ b/Directive.md @@ -66,33 +66,29 @@ Tell ShellCheck where to find a sourced file (since 0.4.0): ``` ### source-path -Give ShellCheck a path on where to search sourced file (since 0.x.x): + +Give ShellCheck a path in which to search for sourced file (since 0.7.0). ```sh +# The script will now look for src/examples/mylib.sh # shellcheck source-path=src/examples -. "$(locate_config)" +. mylib.sh ``` -(similar to the example above) -Additionally, with `source-path=SCRIPTPATH` you can do things like: +The special value `source-path=SCRIPTDIR` will search in the current script's directory, and it can be used as a relative path like `source-path=SCRIPTDIR/../lib`. + +To support the common pattern of `. "$CONFIGDIR/mylib.sh"`, ShellCheck strips one leading, dynamic section before trying to locate the rest. That means that ShellCheck will look for `config.sh` and `utils.sh` in the same directory as this script when it is being checked: ```sh #!/bin/sh -# file: scripts/test.sh - -# shellcheck source-path=SCRIPTPATH -. "$(dirname "$(realpath "$0")")/utils.sh" -``` - -for file layout: -``` -. -└── scripts - ├── test.sh - └── utils.sh +# shellcheck source-path=SCRIPTDIR +here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +. "$here/config.sh" +. "$here/utils.sh" ``` ### shell + Specify the shell for a script (similar to the shebang, if you for any reason don't want to add one) (since [0.4.5](https://github.com/koalaman/shellcheck/issues/581#issuecomment-249437837)): ```sh