[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: |
Tue, 07 Feb 2023 12:33:30 -0500 |
Robert Elz <kre@munnari.OZ.AU> writes:
> | Aliases are not used in bash scripts, unless bash is invoked in POSIX
> | compatibility mode, or the "expand_aliases" shopt is turned on.
>
> I think that's what must have happened ... the infinite loop of
> echo commands suggests that the function definition
>
> cmd() { echo "$@" ; }
>
> was converted by the alias info
>
> echo() { echo "$@" ; }
>
> and when you see that, it is obvious why cmd a b c (which becomes echo a b c)
> just runs echo which runs echo which runs echo which ...
Heh -- but OTOH, if you use
function cmd() { echo "$@" ; }
you *don't* get that behavior.
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.
That makes it clear why the second case behaves as it does. But my
reading of the definition of "simple commands" implies that function
defintions are not simple commands, and alias substitution should not be
done on them (that is, the initial part) in any case.
Dale
- 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, 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, 2023/02/17
- 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