Skip to Content.
Sympa Menu

sm-sorcery - Re: [SM-Sorcery]$IFS

sm-sorcery AT lists.ibiblio.org

Subject: Discussion of Sorcery related topics

List archive

Chronological Thread  
  • From: Jens Laas <jens.laas AT data.slu.se>
  • To: Sergey A Lipnevich <sergeyli AT pisem.net>
  • Cc: Dufflebunk <dufflebunk AT dufflebunk.homeip.net>, <sm-sorcery AT lists.ibiblio.org>
  • Subject: Re: [SM-Sorcery]$IFS
  • Date: Mon, 21 Oct 2002 15:12:31 +0200 (CEST)

(02.10.21 kl.08:09) Sergey A Lipnevich skrev följande till Dufflebunk:

Check this out:

a="a"
while read i ; do
a="${a}${i}"
echo $a
done < <(echo -e "a\nb")
# ^^^^^^^^^^^^^^^^^^^
echo "Final: $a"

Here is the output:
aa
aab
Final: aab

In this case i believe the (echo -e "a\nb") part runs in a subshell.

Cheers,
Jens


See my note on this in the ChangeLog. That's a harsh reality :-( of
bash, but it it possible to circumvent it in many specific cases.

Dufflebunk wrote:

>One odd side effect that I just found is that:
>echo $foo | while read i ; do
> #This is all executed in a sub shell!
>done
>
>Meaning environment modified inside the loop will not persist after the
>loop. Example:
>a="a"
>echo -e "a\nb" | while read i ; do
> a="${a}${i}"
> echo $a
>done
>echo "Final: $a"
>
>Here is the output:
>aa
>aab
>Final: a
>
>Not what you would expect. Although it makes sense when you look at it
>closely, it still surprised me, so I though it might help others too.
>
>

-----------------------------------------------------------------------
'This mail automatically becomes portable when carried.'
-----------------------------------------------------------------------
Jens Låås Email: jens.laas AT data.slu.se
Department of Computer Services, SLU Phone: +46 18 67 35 15
Vindbrovägen 1
P.O. Box 7079
S-750 07 Uppsala
SWEDEN
-----------------------------------------------------------------------





Archive powered by MHonArc 2.6.24.

Top of Page