From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21395 invoked by alias); 31 Aug 2016 10:06:32 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39141 Received: (qmail 22883 invoked from network); 31 Aug 2016 10:06:32 -0000 X-Qmail-Scanner-Diagnostics: from mailout3.w1.samsung.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(210.118.77.13):SA:0(-1.5/5.0):. Processed in 0.431267 secs); 31 Aug 2016 10:06:32 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts) X-AuditID: cbfec7f5-f792e6d0000013f5-a7-57c6ac22a519 Date: Wed, 31 Aug 2016 11:06:20 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: [PATCHv2] [bug] $SHLVL decremented for the last command of a subshell Message-id: <20160831110620.3f298a8c@pwslap01u.europe.root.pri> In-reply-to: <20160830124426.GA15615@chaz.gmail.com> References: <20160822061723.GA7308@chaz.gmail.com> <20160829155156.GB17700@chaz.gmail.com> <160829185505.ZM8699@torch.brasslantern.com> <20160830124426.GA15615@chaz.gmail.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrELMWRmVeSWpSXmKPExsVy+t/xy7pKa46FG7xsErc42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGfvmL2ArWCdScWDyIaYGxvsCXYycHBICJhIzF79jhrDFJC7c W8/WxcjFISSwlFFi+vKFUM4MJokVaw4yQzjnGCX2X9sA5ZxllGh6OJURpJ9FQFWi7/4HdhCb TcBQYuqm2WBxEQEtiR0nTzKB2MICIRJP/t1jAbF5BewlZkxuA4tzAt1xcO57qHVbGSVa9p0H O4pfQF/i6t9PTBAH2kvMvHKGEaJZUOLHZIhBzEALNm9rYoWw5SU2r3kL1iskoC5x4+5u9gmM wrOQtMxC0jILScsCRuZVjKKppckFxUnpuUZ6xYm5xaV56XrJ+bmbGCEh/XUH49JjVocYBTgY lXh4D8w6Gi7EmlhWXJl7iFGCg1lJhPfKqmPhQrwpiZVVqUX58UWlOanFhxilOViUxHln7nof IiSQnliSmp2aWpBaBJNl4uCUamBMyS64w2ip09C050PxtUsahTMKCnd/q7Ew63JOm17B/kT0 pxXbDq+y16svbud7rerytYzNUYbhvzj7kQg7qchcmWuTm09YBsQ1FEuttV90cc83k36OtA6r RIlIW/lXEafLSoo85G9c513t8uvKYlFXoZvZZ0wXnJ4Z1hWqI7Gs6cWEJQU/25VYijMSDbWY i4oTAfdgxwRlAgAA On Tue, 30 Aug 2016 13:44:26 +0100 Stephane Chazelas wrote: > + SHLVL=1 > + $ZTST_testdir/../Src/zsh -fc 'sh -c "echo \$SHLVL"' > + $ZTST_testdir/../Src/zsh -fc '(sh -c "echo \$SHLVL")' > + $ZTST_testdir/../Src/zsh -fc '( (sh -c "echo \$SHLVL"))' > +0:SHLVL decremented upon implicit exec optimisation > +>1 > +>1 > +>1 > + > + SHLVL=1 > + $ZTST_testdir/../Src/zsh -fc '(sh -c "echo \$SHLVL"); exit' > + $ZTST_testdir/../Src/zsh -fc '(exec sh -c "echo \$SHLVL"); exit' > + $ZTST_testdir/../Src/zsh -fc '( (sh -c "echo \$SHLVL"); exit)' > +0:SHLVL not decremented upon exec in subshells > +>2 > +>2 > +>2 > + I should have looked harder before committing... unfortunately, we can't rely on sh *not* incrementing SHLVL because it might be bash. The path of least resistance seems to be use to zsh, who's behaviour we (think we) know, and take the hit of the extra increment, so I've added notes. pws diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index 75ace5a..e779aab 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -1718,24 +1718,26 @@ >2 >2 + # SHLVL is incremented twice and decremented once in between. SHLVL=1 - $ZTST_testdir/../Src/zsh -fc 'sh -c "echo \$SHLVL"' - $ZTST_testdir/../Src/zsh -fc '(sh -c "echo \$SHLVL")' - $ZTST_testdir/../Src/zsh -fc '( (sh -c "echo \$SHLVL"))' + $ZTST_testdir/../Src/zsh -fc $ZTST_testdir/../Src/zsh' -fc "echo \$SHLVL"' + $ZTST_testdir/../Src/zsh -fc '('$ZTST_testdir/../Src/zsh' -fc "echo \$SHLVL")' + $ZTST_testdir/../Src/zsh -fc '( ('$ZTST_testdir/../Src/zsh' -fc "echo \$SHLVL"))' 0:SHLVL decremented upon implicit exec optimisation ->1 ->1 ->1 - - SHLVL=1 - $ZTST_testdir/../Src/zsh -fc '(sh -c "echo \$SHLVL"); exit' - $ZTST_testdir/../Src/zsh -fc '(exec sh -c "echo \$SHLVL"); exit' - $ZTST_testdir/../Src/zsh -fc '( (sh -c "echo \$SHLVL"); exit)' -0:SHLVL not decremented upon exec in subshells >2 >2 >2 + # SHLVL is incremented twice with no decrement in between. + SHLVL=1 + $ZTST_testdir/../Src/zsh -fc '('$ZTST_testdir/../Src/zsh' -fc "echo \$SHLVL"); exit' + $ZTST_testdir/../Src/zsh -fc '(exec '$ZTST_testdir/../Src/zsh' -fc "echo \$SHLVL"); exit' + $ZTST_testdir/../Src/zsh -fc '( ('$ZTST_testdir/../Src/zsh' -fc "echo \$SHLVL"); exit)' +0:SHLVL not decremented upon exec in subshells +>3 +>3 +>3 + # The following tests the return behaviour of parsestr/parsestrnoerr alias param-test-alias='print $'\''\x45xpanded in substitution'\' param='$(param-test-alias)'