Subject: Re: sh arithmetic expression
To: Florian Stoehr <netbsd@wolfnode.de>
From: Simon Burge <simonb@wasabisystems.com>
List: netbsd-users
Date: 12/29/2004 13:09:29
Florian Stoehr wrote:

> the follwing will run with bash, but not with /bin/sh. How to write the 
> increment statement so that /bin/sh will like it? I played around with 
> "let" but without success.
> 
> #!/bin/sh
> i=1
> while [ $i -le $1 ]
> do
>  	echo "Run " $i
>  	i=$[$i+1]  <--- bash can do that, not /bin/sh
> done

Look at the "Arithmetic Expansion" section of sh(1).

Note that $((expr)) is part of Posix, whereas $[expr] appears
to be a bash extension.  Bash also understands $((expr)).

Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD Support and Service:         http://www.wasabisystems.com/