Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created January 23, 2012 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ormaaj/1661392 to your computer and use it in GitHub Desktop.
Save ormaaj/1661392 to your computer and use it in GitHub Desktop.
Bash parsing of redirects on exported functions
#!/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
# vim: set fenc=utf-8 ff=unix ts=4 sts=4 sw=4 ft=sh nowrap et:
~ $ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment