Updated: 07 December 2024
Simple exit status example
#!/bin/bash
date # run date command
status=$? # exit code is in $?
[ $status -eq 0 ] && echo "success" || echo "failure"
set -e
Exit immediately if a pipeline, which may consist of a single simple command, a list, or a compound command returns a non-zero status
#!/bin/bash -e
rm does-not-exist.cs
ls # this command never runs