From 9e9c86e2a21627094124d1d85a47438890f05159 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 16 Sep 2018 09:58:19 -0700 Subject: [PATCH] Created SC2093 (markdown) --- SC2093.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 SC2093.md diff --git a/SC2093.md b/SC2093.md new file mode 100644 index 0000000..f5f1011 --- /dev/null +++ b/SC2093.md @@ -0,0 +1,35 @@ +## Remove "exec " if script should continue after this command. + +### Problematic code: + +```sh +echo "Starting compilation" +exec ./compile +echo "Starting deployment" +exec ./deploy +``` + +### Correct code: + +```sh +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)`](http://man7.org/linux/man-pages/man2/execve.2.html)), 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: + +* StackOverflow: [My shell script stops after exec](https://stackoverflow.com/questions/3877657/my-shell-script-stops-after-exec) \ No newline at end of file