[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: |
Dale R. Worley |
Subject: |
Re: Having an alias and a function with the same name leads to some sort of recursion |
Date: |
Fri, 17 Feb 2023 11:36:49 -0500 |
Chet Ramey <chet.ramey@case.edu> writes:
> 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.
Well, (1) I'm looking at it based on the *documentation*, which says
"simple command". And my essential point is that the documentation
should be adjusted to handle this specific case, viz. alias-izing the
name of a function that one wants to define without a "function"
reserved word. Let me reiterate that, for a lot of these odd points,
I'm much more fussy that the documentation describes what Bash does than
that I particularly prefer the choice the Bash implementation does.
All of that is qualified by (2) The actual workings of aliases are
complicated, and as you note, in the lexing rather than the parsing.
But contrary to my point (1), I'm willing to tell anyone who uses
aliases to modify things that are grammatically salient (rather than
command names) that they are in "here be dragons" territory, it's their
problem if the documentation doesn't clearly delineate what will happen,
and they need to test examples to tell.
So then, (3) What is a practical change to the manual page? The first
three sentences in version 5.1.0(1) are:
ALIASES
Aliases allow a string to be substituted for a word when it is used as
the first word of a simple command. The shell maintains a list of
aliases that may be set and unset with the alias and unalias builtin
commands (see SHELL BUILTIN COMMANDS below). The first word of each
simple command, if unquoted, is checked to see if it has an
alias.
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.)
Dale
- Re: Having an alias and a function with the same name leads to some sort of recursion, Dale R. Worley, 2023/02/07
- Re: Having an alias and a function with the same name leads to some sort of recursion, Dale R. Worley, 2023/02/14
- Re: Having an alias and a function with the same name leads to some sort of recursion, alex xmb ratchev, 2023/02/14
- Re: Having an alias and a function with the same name leads to some sort of recursion, Chet Ramey, 2023/02/16
- Re: Having an alias and a function with the same name leads to some sort of recursion, alex xmb ratchev, 2023/02/16
- Re: Having an alias and a function with the same name leads to some sort of recursion,
Dale R. Worley <=
- Re: Having an alias and a function with the same name leads to some sort of recursion, alex xmb ratchev, 2023/02/17
- Re: Having an alias and a function with the same name leads to some sort of recursion, Chet Ramey, 2023/02/17
- Re: Having an alias and a function with the same name leads to some sort of recursion, Oğuz İsmail Uysal, 2023/02/18
- Re: Having an alias and a function with the same name leads to some sort of recursion, Chet Ramey, 2023/02/20
- Re: Having an alias and a function with the same name leads to some sort of recursion, Martin D Kealey, 2023/02/17
- Re: Having an alias and a function with the same name leads to some sort of recursion, Robert Elz, 2023/02/18