On 4/25/12 10:55 AM, Greg Wooledge wrote:
> On Wed, Apr 25, 2012 at 08:40:11AM -0400, Chet Ramey wrote:
>> Since you're using bash-4.2, you can experiment with the `lastpipe' shopt
>> option. If that's enabled, bash runs the last element of a pipeline in
>> the parent shell context without creating a subshell.
>
> I actually started writing a response that mentioned that, but when I
> was testing it, it didn't seem to work.
>
> The manual says job control has to be off, so I did it as a script:
>
> imadev:~$ cat foo
> #!/bin/bash
> set +m
> shopt -s lastpipe
> echo hi | read foo
> echo "<$foo>"
z4.local(1)$ cat x3
#! ../bash-4.2-patched/bash
shopt -s lastpipe
echo foo | read bar
echo $bar
z4.local(1)$ ../bash-4.2-patched/bash -c 'echo $BASH_VERSION'
4.2.24(9)-release
z4.local(1)$ ../bash-4.2-patched/bash ./x3
foo
z4.local(1)$ ./x3
foo
The set +m doesn't matter, since scripts do not have job control enabled
by default. Adding it doesn't change the behavior.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/