On Wed, 20 Dec 2006, Uwe Dippel wrote: > I needed some little script; and - as usual - tried it out by typing: > i=0 > uplim=10 > while [ $i -lt $uplim ] > do > ((i=i+1)) > echo $i > done > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > 10 > > So good, so far. > So I put the history into a file; added > #!/bin/sh > and ran it. > To my surprise, it is an endless loop printing 0. > Typed again, works. Running the script: endless loop.
(( .. )) is ksh specific. Put #!/bin/ksh in your scritp and you'll be fine. -Otto > > Question: What is missing in the loop ? > FYI: I tried all those variation of $i in the arithmetic expression, but I > won't do the trick. It works properly as line-by-line and loops endlessly > as script. > > I can make it work by changing it to > ... > echo $((i=i+1)) > ... > , but I still ask myself, why the arithmetic expression is not being > evaluated within the script if not in combination with echo, e.g. ? > > Uwe