Is it expected behaviour that x is still 1 in the EXIT trap? #!/bin/sh set -e trap 'echo $x' EXIT x=0 f() { false } x=1 f ~