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

Re: detect pipe

On 2021-02-14 11:33:11 -0800, Bart Schaefer wrote:
> On Sun, Feb 14, 2021 at 9:31 AM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> > Closing stdin is a bad idea, as this can break stdout redirection,
> > and this may be out of control of the commands. See
> >
> >   https://sourceware.org/bugzilla/show_bug.cgi?id=682
> IMO that's just silly.  If stdin/stdout were never supposed to be
> closed, why has the standard shell had <&- and >&- for its entire
> existence?  Why wouldn't those be syntax errors when a file descriptor
> number is not provided if you're never supposed to use them?

To make the rule the same for all file descriptors and all redirection

Note also that something like

  { cat < file } <&-

is OK (the <&- is useless here, but there might be cases where this
could be useful).

In any case, it is a bad idea to use a closed standard fd, unless
you know that this is supported by the command. For instance, note
the difference with "cat" from the GNU coreutils 8.32:

$ echo foo > file
$ cat <&- file -
cat: -: Bad file descriptor
cat: closing standard input: Bad file descriptor
$ cat < /dev/null file -

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