.sh & getopts
Dan Nelson
dnelson at allantgroup.com
Sun Jun 6 01:58:08 UTC 2010
In the last episode (Jun 05), Brandon Gooch said:
> On Sat, Jun 5, 2010 at 6:20 PM, Aiza <aiza21 at comclark.com> wrote:
> > Robert Bonomi wrote:
> >>> From: Aiza <aiza21 at comclark.com>
> >>> Robert Bonomi wrote:
> >>>>> From: Aiza <aiza21 at 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 at allantgroup.com
More information about the freebsd-questions
mailing list