From owner-freebsd-questions@FreeBSD.ORG Fri Jun 4 18:13:28 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 8D8851065674 for ; Fri, 4 Jun 2010 18:13:28 +0000 (UTC) (envelope-from bonomi@mail.r-bonomi.com) Received: from mail.r-bonomi.com (ns2.r-bonomi.com [204.87.227.129]) by mx1.freebsd.org (Postfix) with ESMTP id 2F4708FC1C for ; Fri, 4 Jun 2010 18:13:27 +0000 (UTC) Received: (from bonomi@localhost) by mail.r-bonomi.com (8.14.3/rdb1) id o54ICwto011675; Fri, 4 Jun 2010 13:12:58 -0500 (CDT) Date: Fri, 4 Jun 2010 13:12:58 -0500 (CDT) From: Robert Bonomi Message-Id: <201006041812.o54ICwto011675@mail.r-bonomi.com> To: aiza21@comclark.com, questions@freebsd.org Cc: 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: Fri, 04 Jun 2010 18:13:28 -0000 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}}