On Sun, Sep 09, 2001 at 01:38:00PM -0700, Ulf Zimmermann wrote:
> On Sun, Sep 09, 2001 at 01:11:52PM -0500, Alfred Perlstein wrote:
> > * Ulf Zimmermann <[EMAIL PROTECTED]> [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 ?

Expr could do the trick:

    before=`expr "${ifconfig_args}" : '.*[Dd][Hh][Cc][Pp]\(.*\)'`
    behind=`expr "${ifconfig_args}" : '\(.*\)[Dd][Hh][Cc][Pp].*'`
    other_ifconfig_args="${before}${behind}"

And expr is in /bin.

My EUR 0.024 (~$0.02 :-)

> -- 
> Regards, Ulf.
> 
> ---------------------------------------------------------------------
> Ulf Zimmermann, 1525 Pacific Ave., Alameda, CA-94501, #: 510-865-0204
> 
> To Unsubscribe: send mail to [EMAIL PROTECTED]
> with "unsubscribe freebsd-hackers" in the body of the message

Paul Schenkeveld

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to