|
| From: | Akim Demaille |
| Subject: | local variable escapes into trap |
| Date: | Tue, 29 Dec 2009 10:19:04 +0100 |
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.
| [Prev in Thread] | Current Thread | [Next in Thread] |