bug-bash
[Top][All Lists]
Advanced

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

Re: >&"$var" broken in declare -f and exported functions


From: Alexey
Subject: Re: >&"$var" broken in declare -f and exported functions
Date: Sat, 04 Jun 2022 01:24:39 +0400
User-agent: Mail UserAgent

On 2022-06-03 19:18, Namikaze Minato wrote:
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: x86_64-pc-linux-gnu-gcc
Compilation CFLAGS: -march=native -O2
uname output: Linux ns3012044.ip-37-187-96.eu 4.9.120-xxxx-std-ipv6-64
#327490 SMP Thu Aug 16 10:11:35 UTC 2018 x86_64 Intel(R) Atom(TM) CPU
N2800 @ 1.86GHz GenuineIntel GNU/Linux
Machine Type: x86_64-pc-linux-gnu

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

Description:
  Output redirections to variable file descriptors inside functions
lead to incorrect representation (declare -f). Breaking exported
functions.
  Reproductible with all bash versions from version 4.2 to latest
version including beta.
  Reproductbile on all all platforms.

Repeat-By:
  $ f(){ foo=1; printf test\\n >&"$foo"; }; declare -f f
  f ()
  {
      foo=1;
      printf test\\n &> "$foo"
  }
  $ f
  test
  $ export -f f
  $ bash
  $ ls -l ./1
  ls: cannot access './1': No such file or directory
  $ f
  $ ls -l ./1
  -rw-r--r-- 1 lloyd lloyd 5 Jun  3 17:03 ./1
  $ cat ./1
  test
  $
  The representation of the function is incorrect (&> redirects both
stdin and stdout to files)
  Please note that the function works properly unless you export and
use it or use the output of declare -f.

Hello.

As I can see, problem exist only if we quote "$foo". Without quotes everything looks fine.

As a special case, if n is omitted, and word does not expand to one or more digits or -, the standard output and standard error are redirected as described previously.
I guess this man line is related to this case, and explains why both stdin and stdout redirects occurs together (&>).


Regards,
Alexey



reply via email to

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