Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Aug 2001 14:49:26 -0400
From:      parv <parv_@yahoo.com>
To:        Lucas Bergman <lucas@slb.to>
Cc:        questions@freebsd.org
Subject:   Re: long options in shell script
Message-ID:  <20010817144926.A66962@moo.holy.cow>
In-Reply-To: <20010817132411.D75148@comp04.prc.uic.edu>; from lucas@slb.to on Fri, Aug 17, 2001 at 01:24:11PM -0500
References:  <20010817015201.A26996@moo.holy.cow> <20010817011800.P4232@blossom.cjclark.org> <20010817043458.A28979@moo.holy.cow> <20010817132411.D75148@comp04.prc.uic.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010817144926.A66962>