EN
Bash - break script when some command inside returns error
4 points
In this short article, we would like to show some concept that lets you break Bash script when some command inside returns error.
Assumption: in the below example as error, we understand status different than
0
returned from some program/command.
Practical example:
xxxxxxxxxx
1
2
3
command_1 || exit 1
4
command_2 || exit 1
5
6
if ! command_3
7
then
8
echo "Some error detected!";
9
exit 1
10
fi
11
12
exit 0
Hint: for commands errors you can return different numbers than
1
.