Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer
That is not entirely true, it depend on the type of error. Syntax errors will stop execution for example. – terdon Mar 28 '14 at 16:24
I agree, in general scripts are going to exit with an error code, depends on the syntax and type of error. – bodhi.zazen Mar 28 '14 at 16:37
My bad; I had an incorrect example in my mind. Answer edited. – saiarcot895 Mar 28 '14 at 16:49
Where do I set -e? – becko Jun 24 '14 at 15:46
set -e will apply to all commands you run after that command (unless you unset it). Therefore, you may want to have it at the top of your script file. – saiarcot895 Jun 24 '14 at 15:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.