Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 06 Jun 2010 11:56:17 +0800
From:      Aiza <aiza21@comclark.com>
To:        Dan Nelson <dnelson@allantgroup.com>
Cc:        "questions@freebsd.org" <questions@freebsd.org>
Subject:   Re: .sh & getopts
Message-ID:  <4C0B1C61.9030501@comclark.com>
In-Reply-To: <20100606014737.GG85961@dan.emsphone.com>
References:  <201006051513.o55FDCKj020952@mail.r-bonomi.com> <4C0ADBCF.8040506@comclark.com> <AANLkTimDVOQE-SrT7YO4UD3tktD81jy8px6dbbB83-Dl@mail.gmail.com> <20100606014737.GG85961@dan.emsphone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> /bin/sh can do math on its own:
> 
> flag_count=$((flag_count+1))
> 
> 

I want to know if more that one flag has been coded on the command.
So add 1 to counter if that flag was processed. After all the flags are 
processed and fall out of getopts, then check flag counter for value.

Ok I coded like this


   shift; while getopts biugrs: arg; do case ${arg} in
    b) action="buildworld"; $flag_count=$((flag_count+
    i) action="installworld"; $flag_count=$((flag_count+1));;
    u) action="freebsd-update"; $flag_count=$((flag_count+1));;
    g) action="freebsd-upgrade"; $flag_count=$((flag_count+1));;
    r) action="freebsd-rollback"; $flag_count=$((flag_count+1));;
    s) ezjail_sourcetree=${OPTARG}; $flag_count=$((flag_count+1));;
    ?) exerr ${usage_update};;
    esac; done; shift $(( ${OPTIND} - 1 ))


testing with 4 different flags on the command so should match here.
if $flag_count = 4; then
    echo "yes 4 count"
fi

  exerr "hard stop"



When it runs I get this

=1: not found
0=1: not found
0=1: not found
0=1: not found
0: not found
hard stop


What is still wrong here




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