[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bash 3.2.39] File descriptor 10 is always duplicated from 0 and can
Re: [bash 3.2.39] File descriptor 10 is always duplicated from 0 and cannot be closed
Sun, 02 Nov 2008 17:19:09 -0500
Thunderbird 22.214.171.124 (Macintosh/20080914)
Clark J. Wang wrote:
> When I was doing some testing I found the file descriptor 10 is always
> duplicate of fd 0 and it cannot be closed.
Half right. When a redirection involving fd 0 is evaluated, the shell
has to save fd 0 somewhere so it can be restored. It uses fcntl to
duplicate fd 0 to something above the traditional user-addressable fd
range (0-9). (You can check the code in redir.c:add_undo_redirect(),
which happens to use fds 10 and above).
Since there's no real guaranteed-safe file descriptor range for the
shell's use, it's possible, as you did, to use the fd bash uses to save
fd 0. And since fd 0 is saved before the rest of the redirection is
evaluated, state can change in the middle of the redirection's logical
This doesn't really have anything to do with closing fd 10, which
There are things that the shell can do to try and minimize such collisions,
and bash-4.0 will do a better job at it.
``The lyf so short, the craft so long to lerne.'' - Chaucer
Chet Ramey, ITS, CWRU address@hidden http://cnswww.cns.cwru.edu/~chet/
- Re: [bash 3.2.39] File descriptor 10 is always duplicated from 0 and cannot be closed,
Chet Ramey <=