From owner-freebsd-hackers Mon Sep 10 1: 6:16 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from ringworld.nanolink.com (sentinel.office1.bg [217.75.135.254]) by hub.freebsd.org (Postfix) with SMTP id 2FBBD37B408 for ; Mon, 10 Sep 2001 01:06:03 -0700 (PDT) Received: (qmail 2946 invoked by uid 1000); 10 Sep 2001 08:05:37 -0000 Date: Mon, 10 Sep 2001 11:05:37 +0300 From: Peter Pentchev To: Adrian Filipi-Martin Cc: Ulf Zimmermann , hackers@FreeBSD.ORG Subject: Re: Question about what programs to use in /etc/rc* Message-ID: <20010910110537.A2053@ringworld.oblivion.bg> Mail-Followup-To: Adrian Filipi-Martin , Ulf Zimmermann , hackers@FreeBSD.ORG References: <20010909024721.B1500@seven.alameda.net> <20010909180325.T36056-100000@lorax.ubergeeks.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010909180325.T36056-100000@lorax.ubergeeks.com>; from adrian@ubergeeks.com on Sun, Sep 09, 2001 at 06:06:01PM -0400 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sun, Sep 09, 2001 at 06:06:01PM -0400, Adrian Filipi-Martin wrote: > On Sun, 9 Sep 2001, Ulf Zimmermann wrote: > > > These are some examples strings: > > > > "dhcp" > > "dhcp media 10baseTX" > > "media 10baseTX dhcp mediaopt half-duplex" > > > > The following code will get me inside a if condition: > > > > if [ `expr "${ifconfig_args}" : '.*[Dd][Hh][Cc][Pp].*'` -ne 0 ]; then > > > > .... > > > > fi > > You do everything you need within sh. Someone else pointed out > that case/esac is your friend here. It was not quite complete. Here's > more complete example that will let you pair up the options and their > arguments if they take them. > > ifconfig_args="media 10baseTX dhcp mediaopt half-duplex" > set -- ${ifconfig_args} > while [ $# -gt 0 ]; do > op=$1 > case ${op} in > [Mm][Ee][Dd][Ii][Aa]) > op_arg=$2 > shift > echo "op=media op_arg=${op_arg}" > ;; I don't like this. This second-guessing of ifconfig(8)'s arguments is prone to error - consider the case of a new keyword added to ifconfig(8).. And blindly discarding unrecognized keyword would not really work either - a new keyword might take an argument, the shell script has no way of knowing that, so it would skip the keyword and try to look at its argument as another keyword; what if a keyword takes a string argument of, oh, say, 'dhcp'? :) A ${args#dhcp} might work better, but there is a problem with it - the # match is case-sensitive, and I *know* that there are people using 'dhcp' and people using 'DHCP' :) G'luck, Peter -- This would easier understand fewer had omitted. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message