Math routines (was bourne shell query)
Scott Yelich
scott at tab00.larc.nasa.gov
Mon Sep 3 04:14:26 AEST 1990
>#include <stdio.h>
>int argc; char *argv[];
>while (i <= j)
> printf(" %d",i++);
Hmmm.. that's the STRANGEST sh program I have ever seen...
It must be that CSH that I keep hearing about! :-)
This next routine isn't supposed to be sophisticated... but it works--
just give it two SMALL NUMBERS.
ADDITION ()
{
NUM1="$1"
NUM2="$2"
shift $#
while test $# -lt $NUM1
do
set - x $@
done
NUM1="$@"
shift $#
while test $# -lt $NUM2
do
set - x $@
done
NUM2="$@"
set - $NUM1 $NUM2
TOTAL=$#
}
I am working on a sort of LIBRARY of SHroutines where all I have to do is
include the clode ``. COUNT'' for the next... and use the code.
COUNT ()
{
test $# = 0 &&\
{
echo "$0: Usage: $0 value [...]"
exit 1
} ||\
{
for i
{
set ""
while :
do
set $* " x"
echo $#
if test $# = $i; then
break
fi
done
}
}
}
Of course, ``COUNT x'' is a great counter! :-)
The main problem with the two loops is the ``set " $*"'' command.
This is what takes so much time when the argument list grows.
--
Signature follows. [Skip now]
-----------------------------------------------------------------------------
Scott D. Yelich scott@[xanth.]cs.odu.edu [128.82.8.1]
After he pushed me off the cliff, he asked me, as I fell, ``Why'd you jump?''
Administrator of: Game-Design requests to <game-design-request at cs.odu.edu>
ODU/UNIX/BSD/X/C/ROOT/XANTH/CS/VSVN/
-----------------------------------------------------------------------------
More information about the Comp.unix.shell
mailing list