bash exit code

Updated: 12 February 2023

#!/bin/bash -xv

# run date command
date

# exit code is in $?
status=$?

[ $status -eq 0 ] && echo "success" || echo "failure"

Leave a comment