Skip to content
Joachim Ansorg edited this page Oct 31, 2022 · 2 revisions

You need a line feed or semicolon before the do.

Problematic code:

for file in * do
  echo "$file"
done

Correct code:

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!

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature guerraart8 to find a specific , or see Checks.

Clone this wiki locally