# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	MakeBkup
#	average
#	average.awk
#	sortparams
#	sortparams.sh
#	sum
#	sum.awk
#
echo x - MakeBkup
sed 's/^X//' >MakeBkup << 'END-of-MakeBkup'
X#!/bin/sh
Xdie() {
X	echo "$1" 1>&2
X	exit 1
X}
X
X[ -z "$1" ] && die "No argument"
Xf="$1"
X[ ! -e "$f" ] && die "$f cannot be found!"
X[ -d "$f" ] && die "$f is a directory!"
X
Xif echo $f | egrep -q '\.'; then
X	base=`echo $f | sed 's/^\(.*\)\.[^\.]*$/\1/;'`
X	ext=`echo $f |  sed 's/^.*\(\.[^\.]*\)$/\1/;'`
Xelse
X	base="$f"
X	ext=""
Xfi
X
Xfor n in 3 2 1; do
X	[ -e "$base~$n$ext" ] && mv "$base~$n$ext" "$base~`expr $n + 1`$ext"
Xdone
Xcp "$f" "$base~1$ext"
END-of-MakeBkup
echo x - average
sed 's/^X//' >average << 'END-of-average'
X#!/usr/bin/perl -w
X# Again, too tempting...
Xdie "Wrong number of parameters!" if(!@ARGV || scalar(@ARGV) > 5);
Xmy $sum = 0;
X$sum += $_ foreach(@ARGV);
Xmy $avg = int $sum/scalar(@ARGV);
Xmy $rem = $sum % scalar(@ARGV) * abs($sum)/$sum;
Xprint "The average of ( ",join(' ',@ARGV)," ) is $avg, remainder $rem\n";
END-of-average
echo x - average.awk
sed 's/^X//' >average.awk << 'END-of-average.awk'
X#!/usr/bin/awk -f
X
Xfunction join(sep,a,start,end) {
X	res = a[start];
X	for(i=start+1;i<end;i++) res = res sep a[i];
X	return res;
X}
X
XBEGIN {
X	if(ARGC == 1 || ARGC > 6) {
X		# Ugly, but more portable
X		print "Wrong number of parameters!"|"cat 1>&2"; 
X		exit 1;
X	}
X	for(i=1;i<ARGC;i++) sum += ARGV[i];
X	avg = int(sum/(ARGC-1));
X	rem = sum % (ARGC-1);
X	print "The average of ( " join(" ",ARGV,1,ARGC) " ) is " avg \
X		", remainder " rem ".";
X}
END-of-average.awk
echo x - sortparams
sed 's/^X//' >sortparams << 'END-of-sortparams'
X#!/usr/bin/perl -w
X# Sorry, this just screamed perl
Xdie "Wrong number of parameters!" if(!@ARGV || scalar(@ARGV) > 5);
Xprint join(' ',sort { $a <=> $b} @ARGV),"\n";
END-of-sortparams
echo x - sortparams.sh
sed 's/^X//' >sortparams.sh << 'END-of-sortparams.sh'
X#!/bin/sh
X
Xif [ -z "$1" -o -n "$6" ]; then
X	echo "Wrong number of parameters!" >&2
X	exit 1
Xfi
X
Xecho `while [ "x$1" != "x" ]; do
X	echo "$1"
X	shift
Xdone | sort -n`
END-of-sortparams.sh
echo x - sum
sed 's/^X//' >sum << 'END-of-sum'
X#!/usr/bin/perl -w
X# yet again, too tempting...
Xdie "Wrong number of parameters!" unless(scalar(@ARGV) == 3);
Xmy $sum = 0;
X$sum += $_ foreach(@ARGV);
Xprint "The sum of $ARGV[0], $ARGV[1], and $ARGV[2] is $sum.\n";
END-of-sum
echo x - sum.awk
sed 's/^X//' >sum.awk << 'END-of-sum.awk'
X#!/usr/bin/awk -f
X
XBEGIN {
X	if(ARGC != 4) {
X		# Ugly, but more portable
X		print "Wrong number of parameters!"|"cat 1>&2"; 
X		exit 1;
X	}
X	for(i=1;i<ARGC;i++) sum += ARGV[i];
X	print "The sum of " ARGV[1] ", " ARGV[2] ", and " ARGV[3] " is " sum "."
X}
END-of-sum.awk
exit


