bug-bash
[Top][All Lists]
Advanced

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

Re: value of variable hasn't changed after while loop


From: eD\/ARd0 F/\KEn^M3
Subject: Re: value of variable hasn't changed after while loop
Date: Thu, 7 Nov 2002 10:04:56 -0500

this is in the faq. It's because the pipe symbol actually opens a subshell
with anew environment. The environment is not passed back to the original
calling shell. I usually address by creating a temp file and reading it's
contents later. This not an elegant solution but I am not an elegant shell
coder. I'm sure that there are better solutions.



----- Original Message -----
From: "w3" <w3@hert.org>
To: <bug-bash@gnu.org>
Sent: Thursday, November 07, 2002 4:46 AM
Subject: value of variable hasn't changed after while loop


Hi,


Why can't I change the value of variable after while loop?

#!/bin/sh

A="cde"
cat /etc/passwd | while read line; do
  A="abc" && echo $A
done

echo $A

bash-2.05$ ./test.sh
abc
abc
abc
abc
abc
abc
abc
abc
abc
abc
abc
abc
abc
abc
cde <-- The value of $A hasn't been changed!

Is it a bash bug?

--
w3 <w3@hert.org>
Key ID = 0x5C034369
Key fingerprint = CA07 579E 56A6 9B60 C20E  5B5A 09CE 808A 5C03 4369
http://www.hert.org


_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-bash








reply via email to

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