From owner-freebsd-questions Fri Aug 17 11:50:17 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mtiwmhc25.worldnet.att.net (mtiwmhc25.worldnet.att.net [204.127.131.50]) by hub.freebsd.org (Postfix) with ESMTP id 2BA6F37B421 for ; Fri, 17 Aug 2001 11:50:08 -0700 (PDT) (envelope-from parv@worldnet.att.net) Received: from worldnet.att.net ([32.100.199.176]) by mtiwmhc25.worldnet.att.net (InterMail vM.4.01.03.16 201-229-121-116-20010115) with ESMTP id <20010817185006.XONB5127.mtiwmhc25.worldnet.att.net@worldnet.att.net>; Fri, 17 Aug 2001 18:50:06 +0000 Received: by worldnet.att.net (Postfix, from userid 1001) id DCAC950F46; Fri, 17 Aug 2001 14:49:26 -0400 (EDT) Date: Fri, 17 Aug 2001 14:49:26 -0400 From: parv To: Lucas Bergman Cc: questions@freebsd.org Subject: Re: long options in shell script Message-ID: <20010817144926.A66962@moo.holy.cow> Mail-Followup-To: Lucas Bergman , questions@freebsd.org References: <20010817015201.A26996@moo.holy.cow> <20010817011800.P4232@blossom.cjclark.org> <20010817043458.A28979@moo.holy.cow> <20010817132411.D75148@comp04.prc.uic.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20010817132411.D75148@comp04.prc.uic.edu>; from lucas@slb.to on Fri, Aug 17, 2001 at 01:24:11PM -0500 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG this was, on the fateful occasion around Aug 17 14:24 -0400, sent by Lucas Bergman > > > i got tired of making symlinks to a script and behaving depending on > > basename. > > > > so i am searching for a way to implement long options (bourne > > shell). does anybody have short example or where to find one? > > What does depending on basename have to do with long options? no direct relation, but observe... i was using symlinks to avoid to handle options. creating 4 or more symlinks for each script gets old fast after writing 2 scripts. for example, say 'verbosemail' and 'silentmail' are symlinks to a script 'getmail'... ... myname=`basename $0` case $myname in verbosemail) fetchmail -v | tee -a log ;; silentmail) fetchmail -v > log 2>&1 *) fetchmail ;; esac ... ...other way to do would be to use long options (instead of symlinks) and limit the directory clutter as a side effect. > Anyway, may I first suggest that your script may be outgrowing sh. > For example, Perl has 'use Getopt::Long' that does what you want. at the moment, i don't feel quite comfortable to use perl for functions related to system calls, ie, for functions that are not self contained (inside perl). may be some day. > Failing that, > > if expr "$arg" : --; then > # $arg begins with '--' > fi > > will detect whether $arg begins with '--'. And, > > echo "$arg" | sed 's,^[^=]*=,,' > > will tell you what comes after the (first) '=' sign in $arg. i will keep that in mind. thanks. -- so, do you like word games or scrabble? - parv To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message