4 SC1048
Joachim Ansorg edited this page 2021-11-12 10:35:58 +01:00

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

# Or use the no-op colon operator ":"
if [ -e foo ]
then
  # TODO: handle this
  :
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.