[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bash-bug] A note for read builtin
From: |
Dr. Werner Fink |
Subject: |
Re: [bash-bug] A note for read builtin |
Date: |
Wed, 23 Jun 2010 12:08:20 +0200 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Wed, Jun 23, 2010 at 10:00:12AM +0200, Werner Fink wrote:
> On Tue, Jun 22, 2010 at 04:50:54PM -0400, Chet Ramey wrote:
> > On 6/18/10 10:05 AM, Dr. Werner Fink wrote:
> >
> > > as now is visible the last command in the pipe sequence done
> > > in the bash is a real sub process whereas in the ksh it is not.
> > >
> > > The question rises: Why does the bash require a sub peocess/shell
> > > for the final command of a pipe sequence.
> >
> > It's an implementation decision: the code as it exists today is more
> > straightforward. Since Posix requires that all commands in a pipeline
> > be executed in a subshell environment, though it allows the ksh behavior
> > as an extension, there's been no requirement to change it.
> >
> > If anyone would like to take a shot at changing the code to not fork when
> > executing a command with a pipe for stdin, I'd be glad to take a look at
> > the result.
>
> OK ... after a deeper look into execute_cmd.c I'd like to suggest
> something like in the attachment. Anyone around with a better
> solution? Maybe there is a way to emulate the first pipe commands
> as a named fifo for the last element of the pipe which may avoid
> moving stdin around. Anyway the patch makes things like:
>
> bash/bash-4.1> ./bash -c 'echo a b | while read x y; do a=$x b=$y; done;
> echo $a $b'
> a b
> bash/bash-4.1> ./bash -c 'echo a b | read a b ; echo $a $b'
> a b
>
> work. The change of sh_coproc is simply to avoid a (correct)
> compiler warning.
Yet an other version of the patch to avoid trouble with the
coproc builtin tested out in tests/coproc.tests. There is one
difference more with tests/redir.tests at
exit 3 | $EXIT > $TMPDIR/null-redir-e
echo $? -- ${PIPESTATUS[@]}
testf $TMPDIR/null-redir-e
exit 4 | > $TMPDIR/null-redir-f
echo $? -- ${PIPESTATUS[@]}
testf $TMPDIR/null-redir-f
which now reports
0 -- 3 0
0 -- 4 0
instead of
0 -- 0
0 -- 0
but seems to me ok.
Werner
--
"Having a smoking section in a restaurant is like having
a peeing section in a swimming pool." -- Edward Burr
bash-4.1-pipe.dif
Description: Text Data
- Re: A note for read builtin, (continued)
- Re: A note for read builtin, Roman Rakus, 2010/06/17
- Re: A note for read builtin, Marc Herbert, 2010/06/17
- Re: A note for read builtin, Jan Schampera, 2010/06/17
- Message not available
- Re: A note for read builtin, Jan Schampera, 2010/06/18
- Message not available
- Re: A note for read builtin, Jan Schampera, 2010/06/18
A note for read builtin, Dr. Werner Fink, 2010/06/18