* new version of getopts and a question
@ 1991-10-17 14:52 malte
0 siblings, 0 replies; only message in thread
From: malte @ 1991-10-17 14:52 UTC (permalink / raw)
To: rc
I recently posted my rc version of bourne sh getopts. I'm sorry to say
that this one was in an intermediate state. It did not handle '-n'
correctly. Another error was that error messages were put on stdout.
Now, here is a new enhanced(?) version which regards options like '-xy'
as an error if -x does not expect arguments. If you want getopts to
silently ignore the 'y', comment out
} else if( ~ $^3 -??* ){
echo 'too many arguments to -'$$2 >[1=2].
This will result in full compatibility with the last version.
fn getopts {
if( ~ $#* 0 1 2 ){ return 1 } # no arguments to process
OPTSTRING=`` ($ifs ':') { echo $^1 | sed '1s|.|& |g' };
OPTSTRING='-'^$OPTSTRING;
switch($^3){
case -- ; return 1
case -? ; OPTARG=($^3 $^4)
OPTIND=2
case -??* ; OPTARG=`{echo $^3 | sed '1s|\(..\)\(.*\)|\1 \2|'}
OPTIND=1
case * ; return 1
}
if( ~ $OPTARG(1) $OPTSTRING ){
$2=`` ($ifs '-') { echo -- $OPTARG(1) }
if( ~ $^1 *$$^2:* ){
OPTARG=$OPTARG(2)
if( ~ $#OPTARG 0 ){
echo 'too few arguments to -'$$2 >[1=2]
exit 1
}
} else if( ~ $^3 -??* ){
echo 'too many arguments to -'$$2 >[1=2]
} else {
OPTARG=() OPTIND=1
}
} else {
echo invalid argument $OPTARG(1) >[1=2]
OPTARG='-?'
return 1
}
return 0
}
Now the question: As I understand it,
case -??* ; OPTARG=`{echo $^3 | sed '1s|\(..\)\(.*\)|\1 \2|'}
and
case -??* ; OPTARG=`{sed '1s|\(..\)\(.*\)|\1 \2|' <<< $^3}
should be identical. Am I wrong, or have I discovered a bug?
_______________________________________________________________________________
malte@techfak.uni-bielefeld.de
send mail reply to: Universitaet Bielefeld, Technische Fakultaet
z. Hd. Malte Uhl
Postfach 8640
4800 Bielefeld 1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1991-10-17 14:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-10-17 14:52 new version of getopts and a question malte
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).