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: Fri, 17 Feb 2023 18:05:08 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0

On 2/17/23 11:36 AM, Dale R. Worley wrote:

I think this change covers the case we're talking about, clarifies the
second sentence a bit, and seems to be well-aligned with the more
detailed truth:

        Aliases allow a string to be substituted for a word when it is
        used as the first word of a simple command.  The alias and
        unalias builtin commands (see SHELL BUILTIN COMMANDS below) set
        and unset aliases.  Reserved words may not be aliased, but all
        other tokens may.  A word in a position which could start a
        simple command, if unquoted, is checked to see if it has an
        alias.  (A side effect is that the function name in a function
        definition that does not start with the "function" keyword is
        checked for alias expansion.)

I don't think that actually changes much, and doesn't address the main
point early enough: that aliases get expanded when a word is in a position
to be the first word of a simple command, but hasn't been parsed as such,
and before any tokens following the word are read. (It also has an error.)

How about this, with optional text in brackets:

Aliases allow a string to be substituted for a word that is in
a position [in the input] where it can be the first word of a simple
command. Aliases have names and corresponding values that are set
and unset using the alias and unalias builtin commands (see SHELL
BUILTIN COMMANDS below).

If the shell reads an unquoted word in the right position, it checks
the word to see if it matches an alias name. If it matches, the shell
replaces the word [in the input] with the alias value, and reads that
value as if it had been read [from the input] instead of the word. The
shell doesn't look at any characters following the word before attempting
alias substitution.

The characters '/', '$', '`', '=' and any of the shell metacharacters or
quoting characters listed above may not appear in an alias name.
(and so on)

--
``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]