Updated Directive (markdown)

Vidar Holen
2018-07-28 12:00:22 -07:00
parent c77f360d16
commit 8cd45152a7

@@ -25,9 +25,24 @@ Specify the shell for a script (similar to the shebang, if you for any reason do
# shellcheck shell=sh
echo foo &> bar
Directives that replace or are immediately after the shebang apply to the entire script. Otherwise, they are scoped to the structure that follows it (such as all branches of a `case` statement, or an entire function).
Directives that replace or are immediately after the shebang apply to the entire script. Otherwise, they are scoped to the command that follows it (including compound commands like function definitions, loops and case statements). A directive may only be applied to a complete command, and can not be used immediately preceding an `else` block or `case` branch:
# Directive VALID here, applies to whole `case`
case $1 in
# Directive INVALID, `-v)` is not a complete command
-v)
# Directive VALID here, applies to whole `if`
if [ "$v" ]
then
# Directive VALID here, applies to `die ..` command
die "Only one -v allowed"
# Directive INVALID here, `else` is not a complete command
else
v=1
fi ;;
esac
*Note: There is a [known bug](../issues/1036) in the current version when directives appear within `then` clauses of `if` blocks that causes Shellcheck to report SC1072 on otherwise valid code. Avoid using directives within `then` clauses - instead place them at the top of the `if` block or another enclosing block. This is fixed on the [online version](https://www.shellcheck.net/) and the next release.*
There is no support for scoping a directive to the first structure of the script. In these cases, use a dummy command `true` or `:` and then add directives, such as