[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Exporting functions does not expand aliases in subshells
From: |
Chet Ramey |
Subject: |
Re: Exporting functions does not expand aliases in subshells |
Date: |
Sat, 13 Apr 2024 16:31:34 -0400 |
User-agent: |
Mozilla Thunderbird |
On 4/11/24 11:51 AM, Robert Elz wrote:
For how aliases can mess things up, with the bash way of parsing
command substitutions, if we do:
foo() { echo hello; X=$(echo goodbye); echo "$X"; }
and just run foo then we get "hello", "goodbye" (on successive lines).
Let's assume that this is an interactive shell, not in posix mode, since
those make a difference.
If we then do
alias echo='echo say'
and run foo again (without redefining it) then we get "hello" "say goodbye"
as the first "echo" was already parsed, the (later) alias can't
affect that one, but the one in the command substitution hasn't
been (properly) parsed yet, so the alias affects that.
In posix mode, bash does the same thing as ash-based shells.
As has come up several times before, the ad-hoc way bash used to parse
$()-style command substitutions before bash-5.2 -- which was not POSIX-
conformant, but still needs to be supported for backwards compatibility --
drives the difference in behavior.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature