Bourne shell question
Robert Earl
rearl at gnu.ai.mit.edu
Thu May 9 14:52:39 AEST 1991
In article <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 have to use expr(1) and backquotes:
#!/bin/sh
a=10
b=1
c=`expr $a - $b` # or perl -e "print $a - $b" :-)
echo "a=$a, b=$b, c=$c"
--robert
More information about the Comp.unix.questions
mailing list