From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from techfac.techfak.uni-bielefeld.de ([129.70.1.2]) by archone.tamu.edu with SMTP id <18968>; Thu, 17 Oct 1991 09:53:20 -0500 Received: from dahlie.TechFak.Uni-Bielefeld.DE by techfac.techfak.uni-bielefeld.de (5.65+bind 1.7+ida 1.4.2/tp.29.0890) id AA03297; Thu, 17 Oct 91 15:52:54 +0100 Received: by dahlie.techfak.uni-bielefeld.de (4.1/tp.29.0890) id AA05117; Thu, 17 Oct 91 15:52:52 +0100 Date: Thu, 17 Oct 1991 09:52:52 -0500 From: malte@techfak.uni-bielefeld.de Message-Id: <9110171452.AA05117@dahlie.techfak.uni-bielefeld.de> To: rc@archone.tamu.edu Subject: new version of getopts and a question 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