From 8eb8f048fd115bbdaae85797f25a0d1afe36db00 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Fri, 2 Jul 2021 08:43:31 -0700 Subject: [PATCH] Updated SC1010 (markdown) --- SC1010.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SC1010.md b/SC1010.md index 4d74cd5..c2bd8c5 100644 --- a/SC1010.md +++ b/SC1010.md @@ -1,5 +1,7 @@ ## Use semicolon or linefeed before 'done' (or quote to make it literal). +(or `do` `then`, `fi`, `esac`) + ### Problematic code: ``` @@ -26,9 +28,9 @@ echo "$f is done" ### Rationale: -`done` only works as a keyword when it's the first token of the command. If added after a command, it will just be the literal word "done". +ShellCheck found a keyword like `done`, `then`, `fi`, `esac`, etc used as the argument of a command. This means that the shell will interpret it as a literal string rather than a shell keyword. To be interpreted as a keyword, it must be the first word in the line (i.e. after `;`, `&` or a linefeed). -This is also true for other keywords like `then`. +In the example, `echo "$f" done` is the same as `echo "$f" "done"`, and the `done` does not terminate the loop. This is fixed by terminating the `echo` command with a `;` so that the `done` is the first word in the next line. ### Exceptions