-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 1/23/12 2:50 AM, Dan Douglas wrote:
> 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?

Nope, it's a bug.  The command printing code is a little aggressive about
translating >& to &>.  I've attached a patch that should be enough to
get you by.

Chet
- -- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8gbdQACgkQu1hp8GTqdKuy+wCgkdDB7H/C6gUj1X1q8u/UWang
AnYAn2SoWursp9ew88MBhY5dalLn1gSZ
=lgmc
-----END PGP SIGNATURE-----
*** ../bash-4.2-patched/print_cmd.c	2011-04-21 16:53:01.000000000 -0400
--- print_cmd.c	2012-01-25 15:55:49.000000000 -0500
***************
*** 114,117 ****
--- 114,120 ----
  #define CHECK_XTRACE_FP	xtrace_fp = (xtrace_fp ? xtrace_fp : stderr)
  
+ /* shell expansion characters: used in print_redirection_list */
+ #define EXPCHAR(c) ((c) == '{' || (c) == '~' || (c) == '$' || (c) == '`')
+ 
  #define PRINT_DEFERRED_HEREDOCS(x) \
    do { \
***************
*** 984,987 ****
--- 1000,1004 ----
  {
    REDIRECT *heredocs, *hdtail, *newredir;
+   char *rw;
  
    heredocs = (REDIRECT *)NULL;
***************
*** 1005,1012 ****
  	    hdtail = heredocs = newredir;
  	}
!       else if (redirects->instruction == r_duplicating_output_word && redirects->redirector.dest == 1)
  	{
  	  /* Temporarily translate it as the execution code does. */
! 	  redirects->instruction = r_err_and_out;
  	  print_redirection (redirects);
  	  redirects->instruction = r_duplicating_output_word;
--- 1022,1031 ----
  	    hdtail = heredocs = newredir;
  	}
!       else if (redirects->instruction == r_duplicating_output_word && (redirects->flags & REDIR_VARASSIGN) == 0 && redirects->redirector.dest == 1)
  	{
  	  /* Temporarily translate it as the execution code does. */
! 	  rw = redirects->redirectee.filename->word;
! 	  if (rw && *rw != '-' && DIGIT (*rw) == 0 && EXPCHAR (*rw) == 0)
! 	    redirects->instruction = r_err_and_out;
  	  print_redirection (redirects);
  	  redirects->instruction = r_duplicating_output_word;

Reply via email to