From owner-freebsd-hackers Sun Sep 9 13:52:54 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from infinitive.futureperfectcorporation.com (curie.sunesi.com [196.25.112.244]) by hub.freebsd.org (Postfix) with SMTP id B263337B406 for ; Sun, 9 Sep 2001 13:52:41 -0700 (PDT) Received: (qmail 6618 invoked by uid 0); 9 Sep 2001 20:52:39 -0000 Received: from choke.sunesi.net (HELO gerund.futureperfectcorporation.com) (196.25.112.242) by infinitive.futureperfectcorporation.com with SMTP; 9 Sep 2001 20:52:39 -0000 Received: (qmail 76438 invoked by uid 1001); 9 Sep 2001 20:53:16 -0000 Date: Sun, 9 Sep 2001 22:53:16 +0200 From: Neil Blakey-Milner To: Ulf Zimmermann Cc: Alfred Perlstein , hackers@FreeBSD.org Subject: Re: Question about what programs to use in /etc/rc* Message-ID: <20010909225316.A76366@mithrandr.moria.org> References: <20010909024721.B1500@seven.alameda.net> <20010909131152.L2965@elvis.mu.org> <20010909133800.C1500@seven.alameda.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010909133800.C1500@seven.alameda.net>; from ulf@Alameda.net on Sun, Sep 09, 2001 at 01:38:00PM -0700 Organization: iTouch Labs X-Operating-System: FreeBSD 4.3-RELEASE i386 X-URL: http://mithrandr.moria.org/nbm/ 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 2001-09-09 (13:38), Ulf Zimmermann wrote: > On Sun, Sep 09, 2001 at 01:11:52PM -0500, Alfred Perlstein wrote: > > * Ulf Zimmermann [010909 04:47] wrote: > > > Hello everyone. > > > > > > I am looking at some PRs and I am trying to come up with a solution to > > > submit a patch. I know how to use expr to test as tring in sh inside > > > of a /etc/rc* script, but what method would people recommend to remove > > > part of the string after expr confirmed that something is part of it ? > > > > > > 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 > > > > > > What I would like to do inside the if .. fi is to remove "[Dd][Hh][Cc][Pp]" > > > from the string so that the rest of the options can be used to call ifconfig. > > > Otherwise the if .. fi will test if the string is then empty or just white > > > spaces and if so it will not do anything but set ${dhcp_interfaces}. If its > > > not empty it will call ifconfig with the extra options to set the interface. > > > > > > Awk/sed comes to mind but those are in /usr/bin and I am trying to avoid > > > that. > > > > > > Any suggestions from the more experienced hackers ? > > > > sed? :) > > > > sed 's/[Dd][Hh][Cc][Pp]//g' > > > > -Alfred > > sed is in /usr/bin and so its not a too good idea to use it in a /etc/rc > script. There is sed also in /stand, can that be used ? Nope, you can't. However, you might be able to do it all within sh, by using case and "Parameter Expansion" (see the section in the sh man page). Try this: case ${ifconfig_args} in *[Dd][Hh][Cc][Pp]*) # do stuff with whatever $ifconfig_args=${ifconfig_args%dhcp} ;; esac This probably won't work, since I've not tested it. Casedness is irritating too - dd.sh would advocate converting it all to lowercase with ``dd conv=lcase''. ;) Neil -- Neil Blakey-Milner nbm@mithrandr.moria.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message