On 2/14/23 2:58 PM, Dale R. Worley wrote:
Looking at the manual page, it says

     ALIASES
        Aliases  allow a string to be substituted for a word when it is used as
        the first word of a simple command.

Martin suggested (but IIUC didn't sent to this list):
"Beginning of a simple command" should probably be replaced by something
more along the lines of "beginning of any command that does not start with
a keyword (such as "while", "if", "case", etc) or assignment.

Though I think by "keyword" he means "reserved word".

I think the issue is that he's applying a grammar interpretation (simple
command) to something that is a completely lexical operation. Alias
expansion happens in the lexical analyzer, and it happens when a token
can potentially be the first word of a simple command.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_03_01 tries to make that clear:

"After a token has been delimited, but before applying the grammatical
rules in Shell Grammar, a resulting word that is identified to be the
command name word of a simple command shall be examined to determine
whether it is an unquoted, valid alias name."

You can put any syntax element into an alias and the shell will parse it.
The only POSIX restriction is that you can't alias reserved words.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/


Reply via email to