bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: local variable escapes into trap


From: Akim Demaille
Subject: Re: local variable escapes into trap
Date: Tue, 29 Dec 2009 17:55:00 +0100


Le 29 déc. 09 à 17:35, Chet Ramey a écrit :

On 12/29/09 4:19 AM, Akim Demaille wrote:
Hi!

Hi Chet!

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)

I believe that bash is correct. When the `exit' builtin is invoked, and
the trap is executed, the shell is still executing in the function's
context.  There was no `return', and running exit or a trap does not
implicitly call it.

I figured this out, the behavior is understandable. But is it really desirable? It's one more reason to fear shell-scripts :( You cannot trust the context in which the trap will be run, in particular if you want to read "global" variables (and I do understand that all variables, including those flagged with "local", are actually global).

FWIW, Zsh and Dash behave as I expected.

FWIW, ksh93 behaves like bash.

Well, if this behavior is what you want, I have nothing to add :/

Thanks!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]