From 8cd45152a7b77ef2eaea5d0aa6f4e51f58a6d590 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 28 Jul 2018 12:00:22 -0700 Subject: [PATCH] Updated Directive (markdown) --- Directive.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Directive.md b/Directive.md index 4e97ca5..682f4e2 100644 --- a/Directive.md +++ b/Directive.md @@ -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