Hi!

On the following script, the local variable $name of bar() hides the global $name when entering the trap. I have observed that with several versions of Bash, including

GNU bash, version 4.0.33(1)-release (i486-pc-linux-gnu)


FWIW, Zsh and Dash behave as I expected.

% cat /tmp/foo.sh
#! /bin/sh

trap 'echo "trap: name=$name"' 0

name=main

bar ()
{
    local name=bar
    exit 0
}

bar
% bash /tmp/foo.sh
trap: name=bar

Cheers.


Reply via email to