Re: Bourne Shell: scope of variables in while loop
"Chris F.A. Johnson" <cfajohnson@gmail.com> writes:
> On 2006-08-26, Doug Ritschel wrote:
>> i=0
>> while read line; do
>> i = `expr $i + 1`
>> done < /etc/hosts
>> echo $i
>
> Second, you were not running it (with the error fixed) in a Bourne
> shell. If you were, you would still have seen '0'. In a Bourne
> shell, the redirecion alone is enough to force a subshell.
Are you sure?
$ cat test.sh
i=0
while read line; do i=$(($i + 1)); done </etc/hosts
echo $i
$ ash test.sh
24
$ bash test.sh
24
$ zsh test.sh
24
Any pointers to standards which support your claim?
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
|