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

Re: comment block curiosity



Ray Andrews wrote on Sun, Jan 03, 2021 at 13:31:35 -0800:
> Seems you can't use any characters that are special to the shell tho,

You can, actually:

% zsh -f =(print -rC1 -- 'alias -g "|&"=": <<EOC"' 'echo foo' '|&' 'echo bar' 'EOC' 'echo baz')
foo
baz
% 

IIRC, the relevant difference between «|&» and «# foo» is that the former gets
a token and the latter doesn't.  (The lexer doesn't emit a token for comments
because execution doesn't care about comments.)  You can see this in the output
of «f() { … }; which f», where «|&» is preserved but comments aren't.

tl;dr: It's an issue that's specific to comments.

> it gets confused.

Not really.  An alias was defined that would never be looked up, that's all.
That's not conceptually different from writing, say, «alias 'foo bar'=baz»
(which will never match anything).

Which, incidentally, means that «alias " $k"=$v» is a built-in, global-scope
associative array.  I'm sure that's useful for something.




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