From owner-freebsd-questions@FreeBSD.ORG Wed Jun 29 03:48:36 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BDDAD16A41C for ; Wed, 29 Jun 2005 03:48:36 +0000 (GMT) (envelope-from kdk@daleco.biz) Received: from ezekiel.daleco.biz (southernuniform.com [66.76.92.18]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5D3AC43D1D for ; Wed, 29 Jun 2005 03:48:36 +0000 (GMT) (envelope-from kdk@daleco.biz) Received: from [192.168.2.2] ([69.27.157.226]) by ezekiel.daleco.biz (8.13.1/8.13.1) with ESMTP id j5T3gLgl039937; Tue, 28 Jun 2005 22:42:22 -0500 (CDT) (envelope-from kdk@daleco.biz) Message-ID: <42C21862.6010700@daleco.biz> Date: Tue, 28 Jun 2005 22:41:22 -0500 From: Kevin Kinsey User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.8) Gecko/20050607 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Mike Jeays References: <1120015025.659.12.camel@chaucer> In-Reply-To: <1120015025.659.12.camel@chaucer> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: fbsd_user@a1poweruser.com, "freebsd-questions@FreeBSD. ORG" Subject: Re: Shell script help 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: Wed, 29 Jun 2005 03:48:36 -0000 Mike Jeays wrote: >On Tue, 2005-06-28 at 22:52, fbsd_user wrote: > > >>My sh shell script ability is not that good. >>Have 2 simple coding problems. >> >>How do I code a statement to subtract one from a field. >> >>$rulenum = $rulenum - 1 >>$rulenum = '$rulenum - 1' >> >>one='1' >>$rulenum = $rulenum - $one >>$rulenum='$rulenum - $one' >> >>None of that works. must really be simple. >> >>I also have this line >>inruleno=`ipfw list | sed -n -e "s/00\([0-9]*\) $inblock/\1/p"` >> >>This works ok, the search argument is s/00\ but that is not good enough >>because the number can be 0 to 65535. The sed -n -e "s/00\([0-9]*\ needs to >>be changed to just return the first word. >> >>Thanks for any help you can give. >> >> >> >"man expr" to give the short answer to your first question: > >As an example, x=`expr $x + 1` > >536 ~ $ x=4 >537 ~ $ x=`expr $x + 1` >538 ~ $ echo $ > >Note the back-quotes to execute a command and return the result, and the >need for spaces between each token in the expr command. > > > Hi, Joe, Mike: Mike's right, of course. I dunno if this is a neat trick, or not, but here's a small sample of my fw script that shows not only another use of expr(1), but also the use of expr(1) in a function, since by its very nature it will be called many times (once for each rule, I assume).... ================= # Rule number variable RuleNum=100 ################################# # this function increments $RulNum var by 100... # ################################# inc () { RuleNum=$(expr $1 "+" 100) } ################## # LET'S GET STARTED # ################## # flush the ruleset ... /sbin/ipfw -q flush # set up the loopback ... $FW $RuleNum allow ip from any to any via $loopback inc $RuleNum # deny localhost traffic on other interfaces $FW $RuleNum deny ip from 127.0.0.0/8 to any inc $RuleNum $FW $RuleNum deny ip from any to 127.0.0.0/8 inc $RuleNum ================== HTH, Kevin Kinsey