#!/bin/sh
ls /surely-not-existent$$ 2>/dev/null
if [ "$?" -ne 0 ]; then
echo "$?"
fi
ret=$?
if [ "$ret" -ne 0 ]; then
echo "$ret"
# if is true, ls is fales
if [ "foo" = "foo" ]; then
# but that's still the return of ls and not of fi
echo $?