From owner-freebsd-questions@FreeBSD.ORG Thu May 6 02:34:26 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6B9A3106566C for ; Thu, 6 May 2010 02:34:26 +0000 (UTC) (envelope-from cyberleo@cyberleo.net) Received: from paka.cyberleo.net (paka.cyberleo.net [66.219.31.21]) by mx1.freebsd.org (Postfix) with ESMTP id 45B298FC18 for ; Thu, 6 May 2010 02:34:25 +0000 (UTC) Received: from [172.16.44.4] (h-74-2-96-2.chcgilgm.static.covad.net [74.2.96.2]) by paka.cyberleo.net (Postfix) with ESMTPSA id B8C9628420; Wed, 5 May 2010 22:34:24 -0400 (EDT) Message-ID: <4BE22AAF.8020608@cyberleo.net> Date: Wed, 05 May 2010 21:34:23 -0500 From: CyberLeo Kitsana User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100307 Thunderbird/3.0.3 MIME-Version: 1.0 To: Evuraan References: In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Paul Hoffman , freebsd-questions@freebsd.org Subject: Re: bash while read question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 May 2010 02:34:26 -0000 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. > > $ 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 Furry Peace! - http://wwww.fur.com/peace/