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

Re: Comment (# char) behavior in the sub-shell



On Sep 10,  9:06pm, Peter Stephenson wrote:
}
} I suspect this changed some versions ago now.  At some point we changed
} the way we handled $(...) to parse it better.

I think this is much older than that, and has more to do with the fact
that comments are stripped out before aliases are expanded.  With no
aliasing at all:

torch% echo $ZSH_VERSION
4.2.0
torch% echo $(echo 1 10 # 9)
1 10

To demonstrate that it's not related to global aliasing:

torch% alias #='echo foo'
torch% #
foo
torch% echo X $(# 1 10) Y
X Y
torch% 

} It so happens we don't keep the expanded aliases from the original parse
} in the string we later replay.

If that were the only issue, then removing "#" from $histchars would not
"fix" the problem, I think?

} I'm not sure how much effort this is worth.

Using the comment delimiter as a global alias because interactive shells
don't recognize comments, certainly seems to me to be painting oneself
into a pretty tight corner case.

Still:

torch% echo $(echo $options[interactive])
on
torch% 

so one might ask why no_interactive_comments does not apply.

The following changes it, and all tests still pass, but I'm relatively
sure there is something or other that it breaks.

diff --git a/Src/exec.c b/Src/exec.c
index e2432fd..4230329 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4441,7 +4441,12 @@ getoutput(char *cmd, int qt)
     pid_t pid;
     char *s;
 
-    if (!(prog = parse_string(cmd, 0)))
+    int onc = nocomments;
+    nocomments = (interact && unset(INTERACTIVECOMMENTS));
+    prog = parse_string(cmd, 0);
+    nocomments = onc;
+
+    if (!prog)
 	return NULL;
 
     if ((s = simple_redir_name(prog, REDIR_READ))) {



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