Is execution stopped after an error?
When running a shell script, suppose an error occurs at one line. Are the other lines executed or does the execution of the script stop? I have a script I want to execute with many commands over the week end and I want to make sure if an error occurs at a line, the other lines are executed.
Solution 1:
Execution continues regardless of errors within commands (exit status isn't 0) unless you explicitly specify to stop execution in the event of an error (set -e
). However, in the case of a syntax error, execution stops.
As a general note, if the subsequent commands depend on any of the previous commands being run correctly, then those won't work correctly.
Example (source):
#!/bin/bash
set -e
# Any subsequent(*) commands which fail will cause the shell script to exit immediately