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

Re: bug report: INTERACTIVECOMMENTS option interacts oddly with shell functions in an interactive context



> On 01 September 2021 at 08:55 Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> So here, I'd say:
> 
> ~$ cat a
> echo foo # comment
> echo $(
>   echo bar # comment
> )
> ~$ . ./a
> foo
> ./a:3: bad pattern: #
> 
> is clearly a bug (regression).

Yes, that does seem pretty clear.  Looks easy to fix and test.

Is there anything similar to source that might require attention?
I couldn't think of anything --- source looks like the only case
where we deflect the input from another file without starting a
new shell.

pws

diff --git a/Src/exec.c b/Src/exec.c
index 79d8064b6..1f23a862d 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4622,7 +4622,7 @@ getoutput(char *cmd, int qt)
     char *s;
 
     int onc = nocomments;
-    nocomments = (interact && unset(INTERACTIVECOMMENTS));
+    nocomments = (interact && !sourcelevel && unset(INTERACTIVECOMMENTS));
     prog = parse_string(cmd, 0);
     nocomments = onc;
 
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 88fc8606e..c114ff103 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -944,3 +944,12 @@ F:Note that the behaviour of 'exit' inside try-list inside a function is unspeci
  if : ${(e)a}; then echo x; fi
 1:Status on bad substitution in if without else
 ?(eval):2: bad substitution
+
+ echo 'echo foo # comment
+  echo $(
+  echo bar # comment
+ )' >source_comments.zsh
+ $ZTST_testdir/../Src/zsh -f -o extendedglob -is -c '. ./source_comments.zsh'
+0:Comments should be handled in command subst in interactively sourced files
+>foo
+>bar




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