Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: detect pipe

On 2021-01-30 11:00:15 -0800, Bart Schaefer wrote:
> On Sat, Jan 30, 2021 at 6:27 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> >
> > Cool stuff Bart.  Would you please elaborate on 'Close stdin'?
> ubuntu% ls /dev/fd/0
> /dev/fd/0
> ubuntu% ls /dev/fd/0 <&-
> ls: cannot access '/dev/fd/0': No such file or directory
> File descriptor zero, the standard input, has been closed; it
> literally does not exist for "ls" (in this example).  If it's closed,
> it's not possible to read from it:
> ubuntu% cat <&-
> cat: -: Bad file descriptor
> cat: closing standard input: Bad file descriptor
> Most commands will ignore a closed stdin and behave similarly to
> reading from /dev/null.

Closing stdin is a bad idea, as this can break stdout redirection,
and this may be out of control of the commands. See


Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Messages sorted by: Reverse Date, Date, Thread, Author