Subject: Re: cat(1) question: multiple "-"s
To: Hubert Feyrer <hubert@feyrer.de>
From: Chavdar Ivanov <ci4ic4@gmail.com>
List: netbsd-users
Date: 04/18/2006 16:30:59
On 18/04/06, Hubert Feyrer <hubert@feyrer.de> wrote:
> On Tue, 18 Apr 2006, Chavdar Ivanov wrote:
> > If the user tries to open a file descriptor for reading more than once,
> >       the  shell opens the file descriptor as a pipe to a process that =
copies
> >       all the specified inputs to its output in the order specified,  s=
imilar
> >       to cat, provided the MULTIOS option is set.  Thus
>
> How does zsh know that a file descriptor in its child process is opened?
>
> I imagine something like
>
>         while(read from stdin) { process() }
>         close(stdin)
>         open(stdin from XXX)
>         while(read from stdin) { process() }
>         ...
>
> I wonder how zsh passes to cat what XXX is.

I think it's simpler than that:

root@loan8>   cat - /tmp/4  - - < /tmp/2 < /tmp/3 </tmp/1
22222
22222
22222
22222
33333
33333
33333
33333
33333
33333
33333
11111
4444

It just collects the multiple inputs into a pipe, which gets passed to
the child as and when the FIRST stdin open takes place:

root@loan8>   cat  /tmp/4 - - - < /tmp/2 < /tmp/3 </tmp/1
4444
22222
22222
22222
22222
33333
33333
33333
33333
33333
33333
33333
11111

So it doesn't quite do what seems to be TRT.

>
>
>   - Hubert
>