From owner-freebsd-questions@FreeBSD.ORG Sat Jun 5 12:51:34 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 17C1F1065675 for ; Sat, 5 Jun 2010 12:51:34 +0000 (UTC) (envelope-from aiza21@comclark.com) Received: from avmxsmtp2.comclark.com (avmxsmtp2.comclark.com [202.69.191.116]) by mx1.freebsd.org (Postfix) with ESMTP id C78DB8FC12 for ; Sat, 5 Jun 2010 12:51:31 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlcfAE/lCUzKRa1aPGdsb2JhbAAHh2iWcQEBAQE1vhyFFwSDSA X-IronPort-AV: E=Sophos;i="4.53,366,1272816000"; d="scan'208";a="2129418" Received: from unknown (HELO [10.0.10.3]) ([202.69.173.90]) by avmxsmtp4.comclark.com with ESMTP; 05 Jun 2010 20:51:28 +0800 Message-ID: <4C0A4850.8090107@comclark.com> Date: Sat, 05 Jun 2010 20:51:28 +0800 From: Aiza User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: Robert Bonomi References: <201006041812.o54ICwto011675@mail.r-bonomi.com> In-Reply-To: <201006041812.o54ICwto011675@mail.r-bonomi.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: questions@freebsd.org 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: Sat, 05 Jun 2010 12:51:34 -0000 Robert Bonomi wrote: > m >> From owner-freebsd-questions@freebsd.org Thu Jun 3 23:36:28 2010 >> Date: Fri, 04 Jun 2010 12:35:56 +0800 >> From: Aiza >> To: "questions@freebsd.org" >> Cc: >> Subject: .sh & getopts >> >> 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 )) >> >> >> Command being executed looks like this, cmd action -flags aaaa bbbb >> >> Only a single -flag in allowed on the command. >> >> $# gives a count of parms ie: aaaa bbbb. in this example a count of 2. >> >> I am looking for something to check that holds the number of flags on >> the command. so I can code. if flag_count gt 1 = error >> >> Is there such a thing created by getopts? > > Why bother?? > > flag_count=0 > shift; while getopts :ugr: arg > if flag_count = 1; then > exerr ${cmd_usage} > fi > flag_count=1; > do case ${arg} in > {{blah-blah}} > nope dont work. If the flags are counted at all it has to be a function of getopts