std.sh: a standard shell script skeleton
    Ken Turkowski 
    ken at turtlevax.UUCP
       
    Fri Mar  1 13:47:58 AEST 1985
    
    
  
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 at DECWRL.ARPA
    
    
More information about the Comp.sources.unix
mailing list