Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash: run a script with set -e (errexit)

Tags:

bash

Is there a way to run a bash script with set -e, i.e., as if set -e were in the first line of the script? I know there is for example bash -x to emulate set -x, but I didn't see anything to emulate set -e.

like image 995
asmeurer Avatar asked Jun 12 '13 22:06

asmeurer


1 Answers

bash can use any of the options that are valid with set as a command line option, so you can simply use

bash -e myScript

Here's the first sentence from the Options section of the man page (emphasis mine; I know I glossed over this sentence for a long time as well):

In addition to the single-character shell options documented in the description of the set builtin command, bash interprets the following options when it is invoked:

like image 154
chepner Avatar answered Oct 09 '22 03:10

chepner