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.