mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated Directive (markdown)
28
Directive.md
28
Directive.md
@@ -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
|
||||||
|
Reference in New Issue
Block a user