Bourne Shell (/bin/sh) counting?
Richard John Botting
rbottin at atl.calstate.edu
Mon Mar 19 14:29:52 AEST 1990
Jeff <postnews at cvbnetprime.com> Asks
> What is the best way to provide a loop counter in a Bourne
> shell script? An example script is below, all it needs is
> the count incrementer.
> #!/bin/sh
> count=0
[...]
> # <increment count here>
> echo count=$count
Some people think that this answer is best thought of as a techie joke...
count=`expr $count + 1`
^ ^ ^ ^ ^
The spaces a VERY significant, as are the reversed quotes. However it works
and is useful in several of scripts.
This is even funnier:
count=` echo $count|awk '{print $1 + 1}'`
I'd like to see a neat solution (other than a "increment.c" program).
Dick Botting,
Department of computer science,
California State University, San Bernardino, CA 92407
rbottin at atl.calstate.edu
>INTERNET:rbottin at atl.calstate.edu (Compuserve)
paaaaar at calstate.bitnet
voice:714-880-5327
More information about the Comp.unix.questions
mailing list