Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ncrlnk!ncrstp!npdiss1!mercer From: mercer@npdiss1.StPaul.NCR.COM (Dan Mercer) Newsgroups: comp.unix.shell Subject: Re: bourne shell query Message-ID: <575@npdiss1.StPaul.NCR.COM> Date: 31 Aug 90 19:25:34 GMT References: <26DC6447.15922@maccs.dcss.mcmaster.ca> <8446@orca.wv.tek.com> <8465@orca.wv.tek.com> Reply-To: mercer@npdiss1.StPaul.NCR.COM (Dan Mercer) Organization: StPaul Lines: 81 In article <8465@orca.wv.tek.com> jeff@quark.WV.TEK.COM (Jeff Beadles) writes: :scott@tab00.larc.nasa.gov (Scott Yelich) writes: : :>As a side question, does ANYONE have any bourne shell routines which do :>math... reasonably effeciently? (For numbers > 1000?) : :Well, I use expr. For example: : :a=123456 :b=123 : :c=`expr $a - $b` : :d=`expr $a \* $b` : :echo "c = $c" :echo "d = $d" : :Note, that the '*' MUST be quoted, as the shell will expand it. : :"Shell qouting -- Know it, live it, be it. -Jeff" :-) : : -Jeff :-- :Jeff Beadles jeff@quark.WV.TEK.COM :Utek Engineering, Tektronix Inc. +1 503 685 2568 : SPEEA - Just say no. If your system has named pipes - fifos - and bc then you may find this useful: # # these instructions illustrate how to set up a background # engine in a shell script - a simple application is shown only # for illustration purposes - it numbers lines of standard input # first allocate fifos ITMP=/usr/tmp/i.$LOGNAME OTMP=/usr/tmp/o.$LOGNAME /bin/rm -f $ITMP $OTMP 2>/dev/null /etc/mknod $ITMP p # input fifo for engine /etc/mknod $OTMP p # output fifo for engine # start background engine and open $ITMP as file descriptor 3 # and $OTMP as file descriptor 4 bc <$ITMP >$OTMP & exec 3>$ITMP exec 4<$OTMP # send command to background engine # if background engine is bc, counters can be maintained # echo "x = 1" # echo "x = x + 1" or echo "++x" #the second version returns the new value of x echo "x = 0" >&3 while line=`line` do echo "x++" >&3 # read response read ans <&4 echo "$ans: $line" done < engine # terminate background engine and remove fifos echo "quit" >&3 /bin/rm -f $ITMP $OTMP exit 0 -- Dan Mercer Reply-To: mercer@npdiss1.StPaul.NCR.COM (Dan Mercer) "MAN - the only one word oxymoron in the English Language"