Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site turtlevax.UUCP Path: utzoo!utcs!lsuc!pesnta!amd!turtlevax!ken From: ken@turtlevax.UUCP (Ken Turkowski) Newsgroups: net.sources Subject: std.sh: a standard shell script skeleton Message-ID: <678@turtlevax.UUCP> Date: Thu, 28-Feb-85 22:47:58 EST Article-I.D.: turtleva.678 Posted: Thu Feb 28 22:47:58 1985 Date-Received: Fri, 1-Mar-85 22:35:42 EST Distribution: net Organization: CADLINC, Inc. @ Menlo Park, CA Lines: 76 Hello, you hackers who enjoyed my previous standard C program, stdmain.c. I now bring you a standard /bin/sh script. It is basically an argument parser, and will accept arbitrary argument formats: std -a -l -x -th0 -o outfile - std -alxth0 -ooutfile and related permutations can parse as: -a -l -x -t with argument h0 -o with argument outfile - just like stdmain.c. Convert all of your shell scripts now, so you don't need to remember whether the -o arument should be attached or not! ----------------------------------------------------------------- # This is a shell archive. Remove anything before this line, then # unpack it by saving it in a file and typing "sh file". (Files # unpacked will be owned by you and have default permissions.) # # This archive contains: # std.sh echo x - std.sh cat > "std.sh" << '//E*O*F std.sh//' #! /bin/sh verbose=false files= for arg # Look for flags do while true do case $arg in -) echo NULL FLAG; break ;; -v*) verbose=true ;; -o*) outfile=`expr $arg : '-.\(.*\)'` || outfile=UNKNOWN break ;; -*) echo Unknown flag: \"$arg\" unkflag="$unkflag $arg" break ;; *) case UNKNOWN in $outfile) outfile=$arg ;; *) files="$files $arg" ;; esac break ;; esac arg=-`expr "$arg" : '-.\(.*\)'` || break done done set x $files shift for arg # input file processing template do $verbose && echo processing file \"$arg\" done # The following is just for testing this standard script echo ' Argument' analysis to $0: echo Flags: -v = $verbose, -o = \"$outfile\" echo Unknown flags: $unkflag echo Files: $files //E*O*F std.sh// exit 0 -- Ken Turkowski @ CADLINC, Menlo Park, CA UUCP: {amd,decwrl,nsc,seismo,spar}!turtlevax!ken ARPA: turtlevax!ken@DECWRL.ARPA