bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Having an alias and a function with the same name leads to some sort


From: Chet Ramey
Subject: Re: Having an alias and a function with the same name leads to some sort of recursion
Date: Thu, 16 Feb 2023 10:14:13 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.2

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    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]