From owner-freebsd-questions@FreeBSD.ORG Thu May 6 06:41:36 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 63836106566B for ; Thu, 6 May 2010 06:41:36 +0000 (UTC) (envelope-from evuraan@gmail.com) Received: from mail-px0-f182.google.com (mail-px0-f182.google.com [209.85.212.182]) by mx1.freebsd.org (Postfix) with ESMTP id 39F2D8FC16 for ; Thu, 6 May 2010 06:41:35 +0000 (UTC) Received: by pxi11 with SMTP id 11so2008162pxi.13 for ; Wed, 05 May 2010 23:41:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=gMlJCvIrQKgztCfIe6uRxuLW5nPvjLxv7epFOQJQk6g=; b=Zs59gCOCLDLxvL0cNIEY6gplzr6FH3JETLWIXxBWmgvtFUc7BIs0iyduAHlcvH8YTc kTO4WCmWUXaqLX+yYoDfdsD+IgUjRWPQ0LtGHSJHGfl7yZKt/oY3VJXg/7XH8X3GsSgL Tq1+5vye0fC3KbVRpEeOtXe4vfKgWM8P0f8jc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=GXaEwRwf1Wrg+uEqxvFlSMtza1q97g0Jwqslv5160WT9F4J51WujRf4urzF9i660/f 46ureUqVeKMF5n6XHY9fkuYaYwKrdbx4AIC1XawI2kQ4kZk0Rz9MZfSVRyA93+/YR2Cp nJEuuz2CkajNoNazW7FznGzIG+1kEOZ0A+tjQ= MIME-Version: 1.0 Received: by 10.142.149.39 with SMTP id w39mr1686938wfd.61.1273128089385; Wed, 05 May 2010 23:41:29 -0700 (PDT) Received: by 10.142.142.9 with HTTP; Wed, 5 May 2010 23:41:29 -0700 (PDT) In-Reply-To: References: <4BE22AAF.8020608@cyberleo.net> Date: Wed, 5 May 2010 23:41:29 -0700 Message-ID: From: Evuraan To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=UTF-8 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 06:41:36 -0000 2010/5/5 CyberLeo Kitsana : > 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. > duh, i get it now, anytime stuff is piped , a subshell is evoked: http://tldp.org/LDP/abs/html/subshells.html says, Redirecting I/O to a subshell uses the "|" pipe operator, as in ls -al | (command). thanks for the "reset"..! > -- > Fuzzy love, > -CyberLeo >