Bash complete the first crash

Is there a way to make my bash script complete in the first command that returns a non-zero status?

I know that I can simply associate it with && as follows:

 cd /stuff && echo 'what up' && .... 

Is there another way?

+4
source share
1 answer

Yes, it's as simple as adding at the beginning of your script after shebang:

 set -e 

You can stop this if you want (just a piece of code) with

 set +e 

or on shebang:

 #!/bin/bash -e 

or by calling a script with:

 bash -e script.bash 
+7
source

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


All Articles