bug-bash
[Top][All Lists]
Advanced

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

exit trap inside ksh-style function in bash-2.05b


From: Michael Wang
Subject: exit trap inside ksh-style function in bash-2.05b
Date: Thu, 25 Sep 2003 09:29:12 -0400
User-agent: Mutt/1.4i

(1)

(function t { trap 'printf "%s" a' exit; }; t; printf "%s" b)
=> ba

Per ksh man page:

A trap on EXIT set inside a [ksh-style] function is executed in
the environment of the caller after the function completes.

Also Bolsky and Korn, page 162.

Since bash adopted the ksh-style function, it should follow its
documentation. I see no good reason to be different.

That is, the above shell statement should produce "ab" instead of "ba".

(2)

z=$(function t { trap 'printf "%s" a' exit; }; t; printf "%s" b)
echo $z
=> b

when (...) produces "ba", I find no reason why z=$(...) is not "ba".

bash should be self consistent.

(3)

As a supporting evidence, "zsh version 3.0" that I happen to have
(I am not a zsh user) behaves the same as the correct implementation
of ksh. That is, (1) produces "ab" and $z in (2) is "ab".

And a message on "fix of the exit trap" is found on zsh mailing list
back in 1997:

http://www.zsh.org/mla/workers/1997/msg00205.html

(4)

I do not see this is a standard issue, as the standard does not define
ksh-style function, nor trap inside the function.

Thanks.

-- 
Michael Wang * http://www.unixlabplus.com/ * mwang@unixlabplus.com




reply via email to

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