Bourne shell question

Chip Yamasaki chip at osh3.OSHA.GOV
Fri May 10 11:39:43 AEST 1991


In <1991May8.192623.24160 at bnlux1.bnl.gov> abrams at dan.ccd.bnl.gov (The Ancient Programmer) writes:

>	How does one do a simple computation in a shell script?
>The c-shell does it very neatly. 
>Running:
>	#!/bin/csh
>	set a = 10
>	set b = 1
>	@ c = $a - $b
>	echo "a=$a, b=$b, c=$c"

>produces: a=10, b=1, c=9

>but I've been unable to find out how to do this in the bourne shell.

You don't, exactly.  What you do is use the expr program.  It is slower
because it is external, but it works just fine.  Try

#!/bin/sh
a=10
b=1
c=`expr $a + $b`
echo "a=$a b=$b c=$c"
-- 
--
Charles "Chip" Yamasaki
chip at oshcomm.osha.gov



More information about the Comp.unix.questions mailing list