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: 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



reply via email to

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