Skip to content
koalaman edited this page Oct 17, 2016 · 4 revisions

Can't have empty then clauses (use 'true' as a no-op).

Problematic code:

if [ -e foo ]
then
  # TODO: handle this
fi

Correct code:

if [ -e foo ]
then
  # TODO: handle this
  true
fi

Rationale:

Shells do not allow empty then clauses. They need at least one command (and comments are not commands).

If you want a then clause that does nothing, use a dummy command like true.

Exceptions:

None.

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