On 2022-12-19 23:46:48 +0100, наб wrote:
> I didn't even try the expansion behaviours, because none of them should
> expand, and zsh is wrong to do this (quoting my patch from forwarded-to):
> + * POSIX Issue 7, XCU, 2.3.1 Alias Substitution:
> + *   the command name word of a simple command shall be examined
> + *   to determine whether it is an unquoted, valid alias name
> + * POSIX Issue 7, XCU, 2.2 Quoting:
> + *   The various quoting mechanisms are the escape character,
> + *   single-quotes, and double-quotes.
> 
> As in one /can/ accept anything in the name (XBD, 3.10 Alias Name),
> but /must not/ expand aliases when the word is in any way quoted.

I would say that "\mv" is a quoted version of "mv", but an unquoted
version of "\mv".

I suspect that the POSIX text is based on the fact than normally,
alias names cannot contain quote mechanisms. Otherwise it is rather
ambiguous.

Note also that

  https://pubs.opengroup.org/onlinepubs/9699919799/utilities/alias.html

says: "An alias definition provides a string value that shall replace
a command name when it is encountered", with no restrictions on words
with quoting mechanism.

> > But backslash handling is normally done *after* checking for aliases.
> > This typically allows one to disable an alias by using a backslash:
> 
> Yeah, you're right here; dash conforms to the standard and doesn't
> alias-expand quoted command names, sorry for the confusion.
> 
> (Also, the command name in your last prompt is "mv", so it's doubly
>  weird that zsh allows it to match "\mv".

No, alias substitution is done before quoting mechanisms are involved.
Otherwise one would get an error in the following:

$ alias 'foo=\echo ab'
$ alias
foo='\echo ab'
$ foo
ab

> In sh and ksh compatibility mode, which zsh apparently has, zsh does
> behave like dash/POSIX (allows anything in the name, doesn't expand
> aliases when quoted)).

However, emulation is not perfect. For instance:

zira% emulate ksh
zira% alias '\mv=echo ab'
zira% ksh93
$ alias '\mv=echo ab'
ksh93: alias: \mv=echo ab: invalid alias name

I also suspect that if aliases with backslashes have been defined
before zsh is put in sh/ksh compatibility mode, like that:

zira% alias '\mv=echo ab'
zira% emulate sh
zira% alias
'\mv'='echo ab'
run-help=man
which-command=whence

then such aliases must be ignored in sh/ksh compatibility mode to
avoid some surprises. This can explains the zsh behavior in alias
substitution.

However, in sh/ksh compatibility mode, I would rather expect

  alias '\mv=echo ab'

to give an error, as the alias name is invalid in this context.

BTW, the zsh extension makes sense if one want to be able to alias
some forms of commands with special characters. For instance:

zira% alias '\\foo=echo ab'
zira% \\foo
ab
zira% ""\\foo
zsh: command not found: \foo

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to