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

Re: Aliasing assignment-ish words (aliases[x=y]=z)



Bart Schaefer wrote on Sun, Jan 10, 2016 at 11:19:43 -0800:
> On Jan 1, 12:37am, Daniel Shahaf wrote:
> } Subject: Aliasing assignment-ish words (aliases[x=y]=z)
> }
> }     2	% aliases[x=y]=z 
> }     9	% x=y
> } 
> } Shouldn't line 9 have interpreted the word 'x=y' as an alias?
> 
> No; alias expansion operates on shell words, and in that position
> on the command line "x" "=" and "y" are separate words because of
> assignment syntax rules.  The new treatment of "typeset" as keyword
> extends this to global aliases and "typeset x=y".
> 
> There's more to it than this because "=" and "y" are not subject to
> global alias expansion when they appear in "x=y" but that's the basic
> premise.
> 
> } Or perhaps line 2 should have signaled an error.
> 
> It's long-standing practice that you can create alias table entries for
> things that it's not actually possible to later interpret as aliases.
> This is especially true when assigning to the parameter as you did.
> 
> Basically in this case the rule is that if you break it you get to keep
> the pieces.
> 

Fair enough.

> } Also, the 'alias -L' output for that alias won't work as the code
> } producing the output intended.
> 
> There is no correct output possible in this instance, the alias command
> provides no way to escape the equal sign.  I don't see any reasonable
> alternative except to add a csh-style alias command where the word and
> its expansion can be separate arguments.
> 

I thought we might want to have 'alias -L' handle LHSes with '=' in them
specially: omit them from the output with a warning, or maybe fail hard
with no output at all.  It'd be slightly friendlier than emitting wrong
output (that may override other aliases) letting the user keep both
pieces.

For what it's worth, the real-world use-case behind this thread is
a z-sy-h user whose zshrc has an alias «aliases[=]='noglob ='» and
a function literally named '='.  (That alias works as expected, as
does «aliases[=ls]='…'» even if EQUALS is set.)

Thanks,

Daniel

> That still doesn't help with the assignment-syntax conflict.



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