On 2/18/13 2:55 PM, Stephane Chazelas wrote:

> Bash Version: 4.2
> Patch Level: 37
> Release Status: release
> 
> Moving a file descriptor for a builtin command or a compound
> command leaves the fd closed afterwards:
> 
> $ bash -c ': <&1-; echo test'
> bash: line 0: echo: write error: Bad file descriptor
> 
> expected output: "test".

Thanks for the report.  This has probably been around for as long as those
redirections have been around -- at least 10 years.  I've attached a patch
to fix it.

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/
*** redir.c.old	2013-01-30 11:56:09.000000000 -0500
--- redir.c	2013-02-19 09:38:36.000000000 -0500
***************
*** 1045,1048 ****
--- 1045,1058 ----
  	      REDIRECTION_ERROR (r, errno, -1);
  	    }
+ 	  if ((flags & RX_UNDOABLE) && (ri == r_move_input || ri == r_move_output))
+ 	    {
+ 	      /* r_move_input and r_move_output add an additional close()
+ 		 that needs to be undone */
+ 	      if (fcntl (redirector, F_GETFD, 0) != -1)
+ 		{
+ 		  r = add_undo_redirect (redir_fd, r_close_this, -1);
+ 		  REDIRECTION_ERROR (r, errno, -1);
+ 		}
+ 	    }
  #if defined (BUFFERED_INPUT)
  	  check_bash_input (redirector);

Reply via email to