Updated Directive (markdown)

Vidar Holen
2021-09-18 18:37:51 -07:00
parent ea0eeda767
commit e8cb74cc18

@@ -66,33 +66,29 @@ Tell ShellCheck where to find a sourced file (since 0.4.0):
``` ```
### source-path ### 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 ```sh
# The script will now look for src/examples/mylib.sh
# shellcheck source-path=src/examples # 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 ```sh
#!/bin/sh #!/bin/sh
# file: scripts/test.sh # shellcheck source-path=SCRIPTDIR
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# shellcheck source-path=SCRIPTPATH . "$here/config.sh"
. "$(dirname "$(realpath "$0")")/utils.sh" . "$here/utils.sh"
```
for file layout:
```
.
└── scripts
├── test.sh
└── utils.sh
``` ```
### shell ### 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)): 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 ```sh