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

Re: Macros created via global aliases don't work



On Mon, Aug 12, 2019 at 1:55 AM Aryn Starr <whereislelouch@xxxxxxxxxx> wrote:
>
> alias -g MAGIC=')"'
> alias mdoc='eval "$(m_doc "$*" "$0" '
>
>     mdoc Usage: Some documentation here. MAGIC

You've created an ambiguous "sentence".  Aliases are not really
macros; they are both expanded and parsed left-to-right, not fully
expanded before parsing begins. The ambiguity is that because you've
hidden the closing paren from the parser, it follows through the
depth-first interpretation rather than the breadth-first.

First mdoc expands, and then that expansion is parsed, so now the
parser is now working inside the command substitution, and when MAGIC
expands the shell sees it as part of the m_doc command rather than as
part of the mdoc command, if you see what I mean.

I think you can unambiguously get what you're after by using

alias mdoc='m_doc '
alias -g MAGIC='| { eval "$(read -d "" -r -E)" }'



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