bug-bash
[Top][All Lists]
Advanced

[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:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to stephane_chazelas@yahoo.fr on 9/28/2006 11:16 AM:
> On Thu, Sep 28, 2006 at 09:12:47PM +0600, root@umc.ustu.ru 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."
http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html

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             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
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

iD8DBQFFHJWt84KuGfSFAYARAgoNAKDFOBPp72PC+jMWNTFnsDU5UdFcLwCggboJ
XjgcfV4o0G5xFAKxLBtNW+o=
=BKda
-----END PGP SIGNATURE-----




reply via email to

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