Skip to content
koalaman edited this page Jan 10, 2018 · 2 revisions

Remove indentation before end token (or use <<- and indent with tabs).

Problematic code:

for f in *.png
do
  cat << EOF
     <img src="/proxy/https/web.archive.org/web/20201121032105/https:/github.com/koalaman/shellcheck/wiki/$f" /><br/>
  EOF
done > index.html

Correct code:

for f in *.png
do
  cat << EOF
     <img src="/proxy/https/web.archive.org/web/20201121032105/https:/github.com/koalaman/shellcheck/wiki/$f" /><br/>
EOF
done > index.html

Rationale:

The here document delimiter will not be recognized if it is indented.

You can fix it in one of two ways:

  1. Simply remove the indentation, even though this may break formatting.
  2. Use <<- instead of <<, and indent the script with tabs only (spaces will not be recognized).

Removing the indentation is preferred, since the script won't suddenly break if it's reformatted, copy-pasted, or saved with a different editor.

Exceptions:

If the line was supposed to be a literal part of the here document, consider choosing a less ambiguous token.

ShellCheck

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

Clone this wiki locally
You can’t perform that action at this time.