[Top][All Lists]

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

Re: Reading bytes one-by-one from pipe of process substitution

From: Eric Blake
Subject: Re: Reading bytes one-by-one from pipe of process substitution
Date: Thu, 28 Sep 2006 21:40:32 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20060909 Thunderbird/ Mnenhy/

Hash: SHA1

According to address@hidden on 9/28/2006 11:16 AM:
> On Thu, Sep 28, 2006 at 09:12:47PM +0600, address@hidden wrote:
> [...]
>> Description:
>>         When Process substitution is used, BASH
>>         reads from such descriptor by one bytes!!
> Of course it does. A shell is a shell, it's a command that runs
> other commands.
> So, it's a perfectly normal behavior. That's rather the
> optimisation that is not normal (in the sense that it reads more
> than what you may expect it to).

Not only is it normal, it is required by POSIX:
"When the shell is using standard input and it invokes a command that also
uses standard input, the shell shall ensure that the standard input file
pointer points directly after the command it has read when the command
begins execution. It shall not read ahead in such a manner that any
characters intended to be read by the invoked command are consumed by the
shell (whether interpreted by the shell or not) or that characters that
are not read by the invoked command are not seen by the shell."

For reference, for most apps, POSIX states that on non-seekable file
descriptors, the position of the file pointer is indeterminate when
handing off to another process, in order to allow apps to read a buffer at
a time from the pipe, irretrievably losing data if it doesn't consume it
all.  But this is unacceptable for a shell.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


reply via email to

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