Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!rearl From: rearl@gnu.ai.mit.edu (Robert Earl) Newsgroups: comp.unix.questions Subject: Re: Bourne shell question Summary: expr(1) Message-ID: Date: 9 May 91 04:52:39 GMT References: <1991May8.192623.24160@bnlux1.bnl.gov> Sender: news@ai.mit.edu Organization: (EVIL!) Lines: 25 In-reply-to: abrams@dan.ccd.bnl.gov's message of 8 May 91 19:26:23 GMT In article <1991May8.192623.24160@bnlux1.bnl.gov> abrams@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