bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Closing File Descriptors


From: Chet Ramey
Subject: Re: Closing File Descriptors
Date: Wed, 28 Apr 2004 16:09:43 -0400

> Any idea why doesn't this code close fd 3 like I think the man page says 
> it should under the "REDIRECTION.Duplicating File Descriptors" section
> 
> (linux 2.4's /proc file system)
> 
> #!/bin/bash
> 
> while read -u 3 foo
> do
>         ls -al /proc/$$/fd
>         echo $foo
> 
>         3<&-
> done 3< /etc/hosts

If you want to close fd 3 you need to use `exec 3<&-'.  That makes the
redirections persist in the current shell environment.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
                                                Live...Laugh...Love
Chet Ramey, ITS, CWRU    chet@po.cwru.edu    http://tiswww.tis.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]