plus

if an alias definition ends with a space , when in use , further aliases
may get resolved ( substituded , before parsing code further )

On Fri, Feb 17, 2023, 5:37 PM Dale R. Worley <wor...@alum.mit.edu> wrote:

> Chet Ramey <chet.ra...@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
>
>

Reply via email to