bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Exporting functions does not expand aliases in subshells


From: Philipp Lengauer
Subject: Exporting functions does not expand aliases in subshells
Date: Thu, 11 Apr 2024 11:05:43 +0200

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto
-ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security
-Wall
uname output: Linux TAG009442498805 5.15.0-102-generic #112-Ubuntu SMP Tue
Mar 5 16:50:32 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 16
Release Status: release

Description:

When defining aliases and then exporting a function uses these aliases, the
exported function body has the aliases expanded. This makes sense because
we cannot be sure the same aliases exist in the child process where the
exported function will eventually be used. However, when using subshells in
the child process, the aliases are not expanded. This is unexpected
behavior and potentially breaks the function.

Repeat-By:

# this is a minimal example showing where it works and where it doesnt work
alias echo='echo PREFIX'
echo hello world
 # prints "PREFIX hello world" => OK

foo() { echo "hello world"; }
export -f foo
bash -c 'foo'
# prints "PREFIX hello world" => OK

foo() { output="$(echo "hello world")"; printf '%s\n' "$output"; }
export -f 'foo'
# prints "hello world" => NOT OK (PREFIX missing)


reply via email to

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