From owner-freebsd-questions@FreeBSD.ORG Sun Jun 6 01:58:08 2010 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 05FF41065675 for ; Sun, 6 Jun 2010 01:58:08 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from email1.allantgroup.com (email1.emsphone.com [199.67.51.115]) by mx1.freebsd.org (Postfix) with ESMTP id A370F8FC14 for ; Sun, 6 Jun 2010 01:58:07 +0000 (UTC) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by email1.allantgroup.com (8.14.0/8.14.0) with ESMTP id o561w6fK016253 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 5 Jun 2010 20:58:06 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.4/8.14.4) with ESMTP id o561w6fa000680 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 5 Jun 2010 20:58:06 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.4/8.14.3/Submit) id o561lcnA076135; Sat, 5 Jun 2010 20:47:38 -0500 (CDT) (envelope-from dan) Date: Sat, 5 Jun 2010 20:47:38 -0500 From: Dan Nelson To: Brandon Gooch Message-ID: <20100606014737.GG85961@dan.emsphone.com> References: <201006051513.o55FDCKj020952@mail.r-bonomi.com> <4C0ADBCF.8040506@comclark.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: FreeBSD 8.0-STABLE User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: clamav-milter 0.96 at email1.allantgroup.com X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (email1.allantgroup.com [199.67.51.78]); Sat, 05 Jun 2010 20:58:06 -0500 (CDT) X-Scanned-By: MIMEDefang 2.45 Cc: Aiza , "questions@freebsd.org" , Robert Bonomi Subject: Re: .sh & getopts 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: Sun, 06 Jun 2010 01:58:08 -0000 In the last episode (Jun 05), Brandon Gooch said: > On Sat, Jun 5, 2010 at 6:20 PM, Aiza wrote: > > Robert Bonomi wrote: > >>> From: Aiza > >>> Robert Bonomi wrote: > >>>>> From: Aiza > >>>>> > >>>>> Have this code > >>>>> > >>>>> shift; while getopts :ugr: arg; do case ${arg} in > >>>>>    u) action="freebsd-update";; > >>>>>    g) action="freebsd-upgrade";; > >>>>>    r) action="freebsd-rollback";; > >>>>>    ?) exerr ${cmd_usage};; > >>>>> esac; done; shift $(( ${OPTION} -1 )) > >>>>> > > > > flag_count=0 > > shift; while getopts :ugr: arg; do > >  flag_count + 1; > >  case ${arg} in > >     u) action="freebsd-update";; > >     g) action="freebsd-upgrade";; > >     r) action="freebsd-rollback";; > >     ?) exerr ${cmd_usage};; > >  esac; done; shift $(( ${OPTION} -1 )) > > > > > >  if flag_count gt 3; then > >    exerr ${cmd_usage} > >  fi > > > > > > I think I got the concept correct, but the flag_count + 1 is not correct. I > > get "flag_count: not found" when I run it this way. > > You could use: > > flag_count=`expr $flag_count + 1` /bin/sh can do math on its own: flag_count=$((flag_count+1)) -- Dan Nelson dnelson@allantgroup.com