Subject: Re: ksh vs. pd-ksh and bash
To: None <netbsd-users@netbsd.org>
From: Jukka Salmi <j+nbsd@2007.salmi.ch>
List: netbsd-users
Date: 03/10/2007 09:00:36
Louis Guillaume --> netbsd-users (2007-03-10 01:43:52 -0500):
> Christos Zoulas wrote:
[...]
> > According to the standards the shell is allowed to execute the loop
> > in a subshell. Dependiing on it to be executed in the same shell is
> > non-portable.
> > 
> > christos
> > 
> 
> Ok. That's a real bummer. Is there a better way?

Depending on what you want to do, maybe you could create a function
wich returns the value you're interested in? E.g.:

$ loop()
> {
> local x=0 i
> while read i ;do echo "x = $x"; (( x += i )); echo "new x = $x"; done
> return $x;
> }
$ cat <<END | loop; x=$?
> 1
> 2
> 3
> END
x = 0
new x = 1
x = 1
new x = 3
x = 3
new x = 6
$ echo $x
6


HTH, Jukka

-- 
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~