Skip to content
Joachim Ansorg edited this page Nov 12, 2021 · 2 revisions

Remove exec if script should continue after this command.

Problematic code:

echo "Starting compilation"
exec ./compile
echo "Starting deployment"
exec ./deploy

Correct code:

echo "Starting compilation"
./compile
echo "Starting deployment"
./deploy

Rationale:

The script contains an exec command followed by other commands in the same block. This is likely an error because the script will not resume after an exec command.

Instead, "exec" refers to the Unix process model's idea of execution (see execve(2)), in which the current process stops its current program and replaces it with a new one. This is mainly used in wrapper scripts.

To execute another script or program and then continue, simply drop the exec as in the example.

Exceptions:

If the code after the exec is only there to handle a failure in executing the command you can ignore this warning. For this reason, ShellCheck suppresses the warning if exec is only followed by echo/exit commands.

Related resources:

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