Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Jun 2010 20:47:38 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Brandon Gooch <jamesbrandongooch@gmail.com>
Cc:        Aiza <aiza21@comclark.com>, "questions@freebsd.org" <questions@freebsd.org>, Robert Bonomi <bonomi@mail.r-bonomi.com>
Subject:   Re: .sh & getopts
Message-ID:  <20100606014737.GG85961@dan.emsphone.com>
In-Reply-To: <AANLkTimDVOQE-SrT7YO4UD3tktD81jy8px6dbbB83-Dl@mail.gmail.com>
References:  <201006051513.o55FDCKj020952@mail.r-bonomi.com> <4C0ADBCF.8040506@comclark.com> <AANLkTimDVOQE-SrT7YO4UD3tktD81jy8px6dbbB83-Dl@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jun 05), Brandon Gooch said:
> On Sat, Jun 5, 2010 at 6:20 PM, Aiza <aiza21@comclark.com> wrote:
> > Robert Bonomi wrote:
> >>> From: Aiza <aiza21@comclark.com>
> >>> Robert Bonomi wrote:
> >>>>> From: Aiza <aiza21@comclark.com>
> >>>>>
> >>>>> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100606014737.GG85961>