From owner-freebsd-stable@FreeBSD.ORG Thu Jun 1 14:28:52 2006 Return-Path: X-Original-To: freebsd-stable@freebsd.org Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 35C0016B560 for ; Thu, 1 Jun 2006 14:28:52 +0000 (UTC) (envelope-from michael.schuh@gmail.com) Received: from wx-out-0102.google.com (wx-out-0102.google.com [66.249.82.207]) by mx1.FreeBSD.org (Postfix) with ESMTP id 68C7643D69 for ; Thu, 1 Jun 2006 14:28:40 +0000 (GMT) (envelope-from michael.schuh@gmail.com) Received: by wx-out-0102.google.com with SMTP id i31so206138wxd for ; Thu, 01 Jun 2006 07:28:39 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition; b=oOJflNl+zUcUy9GnbnNx/Nckpbx7/aylHqspc0VO0DPy17V/44UhzPFrooO7qRE0mmfYdiy6BJHp/JMaSu7T3rLlw6dseB87vpAWKYTBLxqBDxL/oOkgZHs0knrjwFmNpda7YB9N/UxY6FShzneeOrMynz1XFtS9E8JeaRxDPb4= Received: by 10.70.73.13 with SMTP id v13mr789475wxa; Thu, 01 Jun 2006 07:28:39 -0700 (PDT) Received: by 10.70.113.4 with HTTP; Thu, 1 Jun 2006 07:28:39 -0700 (PDT) Message-ID: <1dbad3150606010728l379e4c23p1a77558800498806@mail.gmail.com> Date: Thu, 1 Jun 2006 16:28:39 +0200 From: "Michael Schuh" To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Cc: freebsd-stable@freebsd.org Subject: Scope of Variables in sh X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jun 2006 14:28:52 -0000 Hello, i have a little problem with the scope of sheel variables in an script. the script shows like: #!/bin/sh objectcountfile=/data2/scout/objects objectsum=/data2/scout/objcount sometime=5 initialize() { [ ! -e $objectsum ] && touch $objectsum } # countobjects() { myline=0 cat $objectcountfile|grep -v "^[^0-9]*$"|grep -v "^0$"| while read line do myline=`expr $myline + $line` echo $myline > $objectsum done } initialize while true do countobjects clear echo bla bla cat $objectsum sleep $sometime done ##end script this script does what i want, but, i dont really want put the count ($myline) every time he changes in $objectsum. this wasnt really neccessary only the result over all interests me. so my first script was ## countobjects() { myline=0 cat $objectcountfile|grep -v "^[^0-9]*$"|grep -v "^0$"| while read line do myline=`expr $myline + $line` done echo $myline > $objectsum } ## but this doesnt function right. so i see the behavior from $myline in the while-loop like an local variable...... i have searched in man-pages and in google but i have not really good points found. Can anyone give me an ligthshed on this problem? Please answer me directly, i be out of freebsd-hackers. thanks michael