Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 05 May 2010 21:34:23 -0500
From:      CyberLeo Kitsana <cyberleo@cyberleo.net>
To:        Evuraan <evuraan@gmail.com>
Cc:        Paul Hoffman <phoffman@proper.com>, freebsd-questions@freebsd.org
Subject:   Re: bash while read question
Message-ID:  <4BE22AAF.8020608@cyberleo.net>
In-Reply-To: <x2n6fbcd0711005051825mf0835e29jbf5daaab5111b336@mail.gmail.com>
References:  <x2n6fbcd0711005051825mf0835e29jbf5daaab5111b336@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 05/05/2010 08:25 PM, Evuraan wrote:
> I cant figure out why the variable in in loop2 does not hike to +1?
> (its a friday, i am dazed, I admit. but this should not be a mystery!)
> any help would be much appreciated.
> <snip>
> $ cat loop2
> #! /bin/bash
> 
> date > /tmp/somefile
> b="1"
> cat /tmp/somefile | while read blah; do
> let b=(b+1)
> done
> echo "variable is $b"

This particular syntax executes the 'while' block in a subshell. The
variables set or altered in the subshell are never propagated back up to
the parent shell.

-- 
Fuzzy love,
-CyberLeo
Technical Administrator
CyberLeo.Net Webhosting
http://www.CyberLeo.Net
<CyberLeo@CyberLeo.Net>

Furry Peace! - http://wwww.fur.com/peace/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4BE22AAF.8020608>