Bash: run the script using set -e (errexit)

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 that there is, for example, bash -x to emulate set -x , but I have not seen anything to emulate set -e .

+4
source share
2 answers

bash can use any of the parameters that are valid with set as the command line parameter, so you can just use

 bash -e myScript 

Here is the first sentence from the "Parameters" section of the manual page (my attention, I know that I have been silent about this proposal for a long time):

In addition to the one-character shell parameters described in the built-in command description , bash interprets the following parameters when called:

+6
source

How about this:

 (set -e; . file.sh) 
0
source

Source: https://habr.com/ru/post/1485893/


All Articles