Date: Thu, 1 Jun 2006 16:28:39 +0200 From: "Michael Schuh" <michael.schuh@gmail.com> To: freebsd-hackers@freebsd.org Cc: freebsd-stable@freebsd.org Subject: Scope of Variables in sh Message-ID: <1dbad3150606010728l379e4c23p1a77558800498806@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1dbad3150606010728l379e4c23p1a77558800498806>
