Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Bash exit code

#!/usr/bin/env bash

ls  / > /dev/null 2> /dev/null
exit_code=$?
echo $exit_code
if [ $exit_code = 0 ]; then
    echo /
fi

ls  /qqrq > /dev/null 2> /dev/null
exit_code=$?
echo $exit_code
if [ $exit_code = 0 ]; then
    echo /qqrq
fi

Make sure you save the exit code immediaely after the execution of some code if you'd like to use it later, as it always contains the exit code of the most recent statement.