From: Joachim Schmitz <jojo@schmitz-digital.de>
To: git@vger.kernel.org
Subject: Re: t5570 trap use in start/stop_git_daemon
Date: Fri, 13 Feb 2015 08:57:51 +0000 (UTC) [thread overview]
Message-ID: <loom.20150213T094712-477@post.gmane.org> (raw)
In-Reply-To: 20150213080359.GC26775@peff.net
Jeff King <peff <at> peff.net> writes:
>
> On Fri, Feb 13, 2015 at 02:44:03AM -0500, Jeff King wrote:
>
> > On Thu, Feb 12, 2015 at 03:31:12PM -0500, Randall S. Becker wrote:
> >
<snip>
> Hmm, today I learned something new about ksh. Apparently when you use
> the "function" keyword to define a function like:
>
> function foo {
> trap 'echo trapped' EXIT
> }
> echo before
> foo
> echo after
>
> then the trap runs when the function exits! If you declare the same
> function as:
>
> foo() {
> trap 'echo trapped' EXIT
> }
>
> it behaves differently. POSIX shell does not have the function keyword,
> of course, and we are not using it here. Bash _does_ have the function
> keyword, but seems to behave POSIX-y even when it is present. I.e.,
> running the first script:
>
> $ ksh foo.sh
> before
> trapped
> after
>
> $ bash foo.sh
> before
> after
> trapped
>
> $ dash foo.sh
> foo.sh: 3: foo.sh: function: not found
> foo.sh: 5: foo.sh: Syntax error: "}" unexpected
>
> Switching to the second form, all three produce:
>
> before
> after
> trapped
>
> I don't know if that is all helpful to your bug-tracking or analysis,
> but for whatever reason it looks like your ksh is using localized traps
> for both forms of function. But as far as I know, bash has never behaved
> that way (I just grepped its CHANGES file for mentions of trap and found
> nothing likely).
>
> -Peff
>
Both versions produce your first output on our platform
$ ksh foo1.sh
before
trapped
after
$ bash foo1.sh
before
after
trapped
$ ksh foo2.sh
before
trapped
after
$ bash foo2.sh
before
after
trapped
$
This might have been one (or even _the_) reason why we picked bash as our
SHELL_PATH in config.mak.uname (I don't remember, it's more than 2 years
ago), not sure which shell Randall's test used?
bye, Jojo
next prev parent reply other threads:[~2015-02-13 8:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-12 20:31 t5570 trap use in start/stop_git_daemon Randall S. Becker
2015-02-13 7:44 ` Jeff King
2015-02-13 8:03 ` Jeff King
2015-02-13 8:57 ` Joachim Schmitz [this message]
2015-02-13 12:27 ` Randall S. Becker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=loom.20150213T094712-477@post.gmane.org \
--to=jojo@schmitz-digital.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox