Assigning variable value in right behalf of pipeline has no effect

2007-07-05 Thread xandrous

Hi, bash developers!

I've noticed strange bash behaviour. If I assign variable value in
right behalf of pipeline it has no effect. Just try to execute:

XXX=10; { XXX=20; } | read; echo $XXX

XXX=10; { XXX=20; }; echo $XXX

I suppose both of them should output  '20' but the first one outputs
'10'. Is it feature of bug?

This behaviour is the same for at least following bash versions: 2.05,
3.0.16 and the recent 3.2.


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Assigning variable value in right behalf of pipeline has no effect

2007-07-05 Thread Paul Jarc
[EMAIL PROTECTED] wrote:
> XXX=10; { XXX=20; } | read; echo $XXX
>
> XXX=10; { XXX=20; }; echo $XXX
>
> I suppose both of them should output  '20' but the first one outputs
> '10'. Is it feature of bug?

This is normal.  It's explained in entry E4 in the bash FAQ.


paul


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Assigning variable value in right behalf of pipeline has no effect

2007-07-05 Thread xandrous

> XXX=10; { XXX=20; } | read; echo $XXX
>
> XXX=10; { XXX=20; }; echo $XXX
>
> I suppose both of them should output  '20' but the first one outputs
> '10'. Is it feature of bug?

This is normal.  It's explained in entry E4 in the bash FAQ.


Oh, sorry, I made a mistake in the subject, it should have been "left
half" of pipeline. Anyway the examples were right and I have already
read E4 entry of the FAQ but I still couldn't understand the results.

It's clear that 'read' is executed as an separate process and its
result (REPLY variable value) is lost but 'XXX=20'  command is done by
the same process as 'XXX=10'. And if it's so why the 'XXX=20' command
has no effect in the first example? Only because it's done as part of
the pipeline?


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Assigning variable value in right behalf of pipeline has no effect

2007-07-05 Thread Paul Jarc
[EMAIL PROTECTED] wrote:
>> > XXX=10; { XXX=20; } | read; echo $XXX
>
> It's clear that 'read' is executed as an separate process and its
> result (REPLY variable value) is lost but 'XXX=20'  command is done by
> the same process as 'XXX=10'.

No, every element of a pipeline is executed in its own process.  So
the only commands that are executed in the main shell process are
"XXX=10" and "echo $XXX".


paul


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Assigning variable value in right behalf of pipeline has no effect

2007-07-05 Thread xandrous

That's sad. Thank you anyway.


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash