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: Robert Elz
Subject: Re: Having an alias and a function with the same name leads to some sort of recursion
Date: Mon, 02 Jan 2023 22:25:43 +0700

    Date:        Mon, 2 Jan 2023 10:02:45 -0500
    From:        Greg Wooledge <greg@wooledge.org>
    Message-ID:  <Y7LyFT9RNlDUiKDS@wooledge.org>

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

Whether POSIXLY_CORRECT is in the environment (that's what I did to get
the described behaviour) or for some other reason bash is set up to
operate in posix mode, it is fairly clear that is what happened.

Yet another reason to never use aliases, for anything, anywhere, they're
an abomination, and rarely accomplish what one might expect.

kre




reply via email to

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