From owner-freebsd-hackers Mon Sep 10 9:35:33 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from seven.Alameda.net (seven.Alameda.net [64.81.63.137]) by hub.freebsd.org (Postfix) with ESMTP id 67FDC37B408 for ; Mon, 10 Sep 2001 09:35:24 -0700 (PDT) Received: by seven.Alameda.net (Postfix, from userid 1000) id 3801C3A212; Mon, 10 Sep 2001 09:35:24 -0700 (PDT) Date: Mon, 10 Sep 2001 09:35:24 -0700 From: Ulf Zimmermann To: Adrian Filipi-Martin , Ulf Zimmermann , hackers@FreeBSD.ORG Subject: Re: Question about what programs to use in /etc/rc* Message-ID: <20010910093524.D1500@seven.alameda.net> Reply-To: ulf@Alameda.net References: <20010910110537.A2053@ringworld.oblivion.bg> <20010910102943.N36056-100000@lorax.ubergeeks.com> <20010910181954.G1983@ringworld.oblivion.bg> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010910181954.G1983@ringworld.oblivion.bg>; from roam@ringlet.net on Mon, Sep 10, 2001 at 06:19:54PM +0300 Organization: Alameda Networks, Inc. X-Operating-System: FreeBSD 4.3-STABLE 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 Mon, Sep 10, 2001 at 06:19:54PM +0300, Peter Pentchev wrote: > On Mon, Sep 10, 2001 at 11:03:41AM -0400, Adrian Filipi-Martin wrote: > > On Mon, 10 Sep 2001, Peter Pentchev wrote: > > > > > 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'? :) > > > > Sorry, but my example was meant to be more featureful than > > necessary and let you strip it down, sinice you needs wern't completely > > clear. If you just want to test for a substring, try this instead: > > > > case "${ifconfig_args}" in > > *[Dd][Hh][Cc][Pp]*) > > echo "we are using dhcp..." > > ;; > > esac > > > > > > > > > > A ${args#dhcp} might work better, but there is a problem with it - > > > > The pattern after the # is a regular glob pattern. You can use > > ${args#[Dd][Hh][Cc][Pp]} to deal with case. > > > > You probably really meant to say '${args##*[Dd][Hh][Cc][Pp]*}' > > which will collapse to a null string if 'dhcp' is in the string, or the > > string is empty to begin with. With only a single # and no *'s, you will > > not modify the string unless it is exactly "dhcp". > > > > Sill I don't recommend this approach, since you need to test the > > string twice, once before and once after the expansion. The case/esac > > idiom is pretty common as well. > > I think that the original poster is interested in first testing for > 'dhcp' in the string, and then removing it - the original post mentioned > a PR sweep, and I really think he means PR 30441. To correctly process > an ifconfig_rl0="dhcp media 10baseT/UTP", you'd first have to match > it against [Dd][Hh][Cc][Pp], and then remove the 'dhcp' part to get > the real arguments to add to the ifconfig line. > > Come to think of it, it might be as easy as: [**UNTESTED**] > > case ${ifconfig_args}; in > [Dd][Hh][Cc][Pp]*) > set $ifconfig_args > shift > ifconfig_add_args="$*" > ...... > > ..provided there is a requirement that the ifconfig_args should *start* > with 'dhcp' (which would be easy enough to meet - right now, the args > have to *be* 'dhcp', so any additional arguments would be stapled on at > the end). This sounds as the best solution. This would allow to set an interface to be DHCP (variable dhcp_interfaces get set) and take the rest of the arguments (like media/mediaopt) and apply them to the interface before the dhclient gets started. > > G'luck, > Peter > > -- > If wishes were fishes, the antecedent of this conditional would be true. > -- Regards, Ulf. --------------------------------------------------------------------- Ulf Zimmermann, 1525 Pacific Ave., Alameda, CA-94501, #: 510-865-0204 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message