Skip to main content

Errors in shell scripts

Exit on any error

Execute a sequence of shell commands and exit on any error occurred:

#!/bin/bash

set -e

command1
command2
command3

Catch errors

Execute some code in case an error occurs:

#!/bin/bash

if ! some_command; then
echo "Error executing some_command"
some_other_command
fi