Reputation: 41
Is there a way to make my bash script terminates on the first command that returns non-zero status?
I know I can just chain it with &&
's like:
cd /stuff &&
echo 'what's up' &&
....
Is there another way?
Upvotes: 4
Views: 101
Reputation: 185179
Yes, this is that simple as adding at the beginning of your script after the shebang :
set -e
You can stop this if you want (for just a portion of code) with
set +e
or on the shebang :
#!/bin/bash -e
or by calling the script with :
bash -e script.bash
Upvotes: 8