[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug] Bash translates >&$var into &>$var for exported functions.
From: |
Dan Douglas |
Subject: |
[bug] Bash translates >&$var into &>$var for exported functions. |
Date: |
Mon, 23 Jan 2012 01:50:41 -0600 |
User-agent: |
KMail/4.7.4 (Linux/3.1.6-pf; KDE/4.7.4; x86_64; ; ) |
Hello, In the case of exported functions, Bash interprets a copy descriptor
followed by an expansion as the >& synonym for &>, resulting in the output
going to a file named as the value of the FD it's given. This only applies to
">&$var" and not "<&$var". I've tested various quoting, Is there some way
around this?
Gist over here if it's easier to read: https://gist.github.com/1661392
TESTCASE (Overwrites the file named "3" in CWD):
#!/usr/bin/env bash
set -x
f() {
echo 'hi'
} >&${1}
{ f 3; cat; } <<<'' 3>/dev/stdin
export -f f
export -pf
PS4='* ' BASH_XTRACEFD=4 bash -xc 'f 3; cat' <<<'' 3>/dev/stdin 4>&2
[[ -f 3 ]] && cat ./3
END TESTCASE
OUTPUT:
~ $ rm 3; ./exbug
+ f 3
+ echo hi
+ cat
hi
+ export -f f
+ export -pf
f ()
{
echo 'hi'
} &>${1}
declare -fx f
* PS4='* '
* BASH_XTRACEFD=4
+ bash -xc 'f 3; cat'
* f 3
* echo hi
* cat
+ [[ -f 3 ]]
+ cat ./3
hi
END OUTPUT
Bash v. 4.2 w/ patchset 20 on Gentoo Linux amd64.
--
Dan Douglas
signature.asc
Description: This is a digitally signed message part.
- [bug] Bash translates >&$var into &>$var for exported functions.,
Dan Douglas <=