MPE/iX Shell and Utilities Reference Manual, Vol 2

sh(1) MPE/iX Shell and Utilities sh(1)
EXAMPLES
Software distributed over computer networks such as Usenet is often distributed in a form
known as a shell archive. In essence, a shell archive is a shell script containing the data of
one or more files, plus commands to reconstruct the data files and check that the data was
transmitted correctly. The following shows a sample shell archive.
# This is a shell archive.
# It contains the one file "frag.ksh"
# To extract contents, type
# sh file
#
if [ -f frag.ksh ]
then echo frag.ksh exists: will not overwrite
else
echo extracting frag.ksh
sed ’s/ˆX//’ >frag.ksh <<_EOF_
X# This is frag.ksh
X# Not very interesting, really.
Xecho frag.ksh here!
_EOF_
if [ "`sum frag.ksh|awk ’{print $1}’`" != 52575 ]
then echo frag.ksh damaged in transit
fi
fi
The following simple scripts produces as much of the Fibonacci sequence as can be calculated
using integers.
# Print out Fibonacci sequence; start sequence
# with first two positional parameters:
# default 1 1
typeset –i x=${1:–1} y=${2:–1} z
while[x–gt0]#until overflow
do
echo $x
let z=y+x x=y y=z
done
Commands and Utilities 1-541