dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Harald van Dijk <harald@gigawatt.nl>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: DASH shell mailing list <dash@vger.kernel.org>
Subject: Re: EXIT trap handling in subshells broken
Date: Fri, 17 Jan 2020 22:58:42 +0000	[thread overview]
Message-ID: <a7c19de3-b34c-6ef1-b116-1f16cbad76f4@gigawatt.nl> (raw)
In-Reply-To: <20200117101532.jlddos2uctne5xk7@gondor.apana.org.au>

On 17/01/2020 10:15, Herbert Xu wrote:
> On Mon, Jan 06, 2020 at 09:57:20PM +0000, Harald van Dijk wrote:
>>
>> The problem is not limited to redirections:
>>
>>    f() { (trap "echo \$var" EXIT); }
>>    var=bad
>>    var=ok f
>>
>> This prints "bad", when it should print "ok". Here, the local variable is
>> dropped not in main(), but during the unwind process.
> 
> This works fine for me with the latest git tree.  This is because
> reset has now been split into exitreset and reset and variables
> are only reset in reset() which is only called if exitshell is
> not happening.
> 
> As if we're in a subshell we will never take the reset() path
> I don't think we need to do anything here at all.

Ah, right, forgot about that. That change also altered the behaviour of

   trap "echo foo=\$foo" EXIT
   f() {
     local foo=bar
     exit
   }
   f

though, which printed foo= in released versions of dash since at least 
as far back as 0.5.1, and prints foo= in current versions of bash and 
zsh. It now prints foo=bar. That is defensible and also what some other 
shells do, but I'm not sure it's intended.

(Combined with some other changes I have, the behaviour stops being 
defensible, but I suspect that is nothing that affects dash.)

Cheers,
Harald van Dijk

      reply	other threads:[~2020-01-17 22:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <c1a9c062-0917-d3f3-8826-811b5a4fd802@gigawatt.nl>
2020-01-17  8:51 ` Herbert Xu
2020-01-17  9:57   ` [PATCH] redir: Clear saved redirections in subshell Herbert Xu
2020-01-17 15:28     ` [v2 PATCH] " Herbert Xu
2020-01-17 23:11       ` Harald van Dijk
2020-01-19 10:21       ` [v3 " Herbert Xu
2020-01-17 10:15 ` EXIT trap handling in subshells broken Herbert Xu
2020-01-17 22:58   ` Harald van Dijk [this message]

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=a7c19de3-b34c-6ef1-b116-1f16cbad76f4@gigawatt.nl \
    --to=harald@gigawatt.nl \
    --cc=dash@vger.kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --subject='Re: EXIT trap handling in subshells broken' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).