#!/bin/bash echo "first try" # command with return code != 0 (so, failed) false echo "rc: $?" # beware! now $? is set by echo if [ $? -ne 0 ] ; then echo "command failed." else echo "command successfully executed." fi #### echo "next try" false RC=$? echo "rc: $RC" if [ $RC -ne 0 ] ; then echo "command failed." else echo "command successfully executed." fi