From 45e7d232c6aafb8dfa13ca4d61bf720f8a87c463 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 19 Oct 2022 20:40:44 -0700 Subject: [PATCH] Created SC1063 (markdown) --- SC1063.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 SC1063.md diff --git a/SC1063.md b/SC1063.md new file mode 100644 index 0000000..526a800 --- /dev/null +++ b/SC1063.md @@ -0,0 +1,42 @@ +## You need a line feed or semicolon before the 'do'. + +### Problematic code: + +```sh +for file in * do + echo "$file" +done +``` + +### Correct code: + +```sh +for file in *; do + echo "$file" +done + +# or + +for file in * +do + echo "$file" +done +``` +### Rationale: + +ShellCheck found a `do` on the same line as a loop, but `do` only starts a loop block at the start of a line/statement. Make the `do` the start of a new line/statement by inserting a linefeed or semicolon in front of it. + +### Exceptions: + +If you wanted to treat `do` as a literal string, you can quote it to make this clear to ShellCheck and humans: + +``` +for f in "for" "do" "done" +do + echo "Shell keywords include: $f" +done +``` + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file