You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
wileyhy edited this page Oct 6, 2024
·
13 revisions
Use semicolon or linefeed before done (or quote to make it literal).
(or dothen, fi, esac)
Problematic code:
forfin*;doecho"$f"done
or
echo$f is done
Correct code:
forfin*;doecho"$f";done
or
echo"$f is done"
Rationale:
ShellCheck found a keyword like done, then, fi, esac, etc used as the argument of a command. This means that the shell will interpret it as a literal string rather than a shell keyword. To be interpreted as a keyword, it must be the first word in the line (i.e. after ;, & or a linefeed).
In the example, echo "$f" done is the same as echo "$f" "done", and the done does not terminate the loop. This is fixed by terminating the echo command with a ; so that the done is the first word in the next line.
Exceptions
If you're intentionally using done as a literal, you can quote it to make this clear to ShellCheck (and also human readers), e.g. instead of echo Task is done, use echo "Task is done". This makes no difference to the shell, but it will silence this warning.