Re: Assign variable to variable ? Why doesn't this work?

From: Icarus Sparry (usenet_at_icarus.freeuk.com)
Date: 01/28/04


Date: Wed, 28 Jan 2004 04:28:51 GMT

On Tue, 27 Jan 2004 11:34:49 -0500, Mark wrote:

> I'm using bash. Specifically, the last echo returns nothing. What am I
> missing? If I do this manually (assign variable to another variable) it
> works.
>
>
> ps -ef |grep -i searchtext|grep -i $remote |while read a b c d e f g h i j
> do
> echo $b $j
> pid=$b
> remotename=$j
> done
>
> echo $pid $remotename

ps -ef |grep -i searchtext|grep -i $remote | {
  while read a b c d e f g h i j
    do
      echo $b $j
      pid=$b
      remotename=$j
    done
  
  echo $pid $remotename
}

As others have said, the problem is subshells. With a couple of extra
characters you can get the subshells created as you wish.