<p>I have a shell script that executes a number of commands. How do I make the shell script exit if any of the commands exit with a non-zero exit code?</p>

In Bash this is easy. Just tie them together with
```
&&
```
:
```
```
command1 && command2 && command3
```
```
You can also use the nested
if
construct:
```
```
if command1
   then
       if command2
           then
               do_something
           else
               exit
       fi
   else
       exit
fi
```
```