2008, Feb 28 -> Fried Zoltan wrote :
> while-al irtam egy adatbeolvasast amikor is szamomra fura dolgot 
> kezdett muvelni a bash.
> lent egy tesztprogi is ua muvelte. csak nem ertem miert ?
> 
> a="1\n2\n3";
> x=a
> 
> echo x=$x
> 
> echo -e $a | while read i; do
>     echo i=$i
>     if [ $i = "2" ]; then x=b; echo x=$x; fi
> done
> 
> echo x=$x
> 
> for i in `echo -e $a`; do
>     echo i=$i
>     if [ $i = "2" ]; then x=b; echo x=$x; fi
> done
> echo x=$x
> 
> result:
> x=a
> i=1
> i=2
> x=b
> i=3
> x=a <-itt nem b-nek kellene lennie??
> i=1
> i=2
> x=b
> i=3

hello,

mivel a '| while read' reszlet subshellben fut a pipe miatt, ezert nem
a kivul definialt x-edet valtoztatod, es erintetlen marad az x-ed a
kulonallo 'echo x=$x' vegrehajtasakor

Atti


_________________________________________________
linux lista      -      [email protected]
http://mlf2.linux.rulez.org/mailman/listinfo/linux

válasz