From owner-freebsd-hackers Sun Sep 9 15: 6:13 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from lorax.ubergeeks.com (lorax.ubergeeks.com [209.145.65.55]) by hub.freebsd.org (Postfix) with ESMTP id 608B637B403 for ; Sun, 9 Sep 2001 15:06:05 -0700 (PDT) Received: from localhost (adrian@localhost) by lorax.ubergeeks.com (8.11.6/8.11.6) with ESMTP id f89M61k36100; Sun, 9 Sep 2001 18:06:01 -0400 (EDT) (envelope-from adrian@ubergeeks.com) Date: Sun, 9 Sep 2001 18:06:01 -0400 (EDT) From: Adrian Filipi-Martin Reply-To: Adrian Filipi-Martin To: Ulf Zimmermann Cc: Subject: Re: Question about what programs to use in /etc/rc* In-Reply-To: <20010909024721.B1500@seven.alameda.net> Message-ID: <20010909180325.T36056-100000@lorax.ubergeeks.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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, 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}" ;; [Mm][Ee][Dd][Ii][Aa][Oo][Pp][Tt]) op_arg=$2 shift echo "op=mediaopt op_arg=${op_arg}" ;; [Dd][Hh][Cc][Pp]) echo "do something dhcp specific..." ;; *) echo "unknown op: ${op}" ;; esac shift done cheers, Adrian -- [ adrian@ubergeeks.com ] To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message