This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Problem with shell script
- From: René Berber <rberber at prodigy dot net dot mx>
- To: cygwin at cygwin dot com
- Date: Sun, 24 Jul 2005 15:05:20 -0500
- Subject: Re: Problem with shell script
- References: <20050724191302.58251D10DB@rekin6.o2.pl>
Marek wrote:
> When I put commands below in command line:
> i=1
> echo $i
> i=$(($i+1))
> echo $i
>
> everything works well (i is incremented from 1 to 2), but when I run this as a shell script the result is:
> 1+1 instead of 2
>
> How should I do incrementation in shell script?
It depends on what shell and version you are using.
In bash (version > 2.05) I use:
let i=i+1
And you can also do it inside a loop, like:
for (( i= 1; i <= $3; i++ )); do
...
those double parenthesis are not available in old bash versions.
HTH
--
René Berber
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/