Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCHv2] [bug] $SHLVL decremented for the last command of a subshell



On Tue, 30 Aug 2016 13:44:26 +0100
Stephane Chazelas <stephane.chazelas@xxxxxxxxx> 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)'



Messages sorted by: Reverse Date, Date, Thread, Author