| delorie.com/archives/browse.cgi | search |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
| To: | cygwin AT cygwin DOT com |
| From: | =?ISO-8859-2?Q?Ren=E9_Berber?= <rberber AT prodigy DOT net DOT mx> |
| Subject: | Re: Problem with shell script |
| Date: | Sun, 24 Jul 2005 15:05:20 -0500 |
| Lines: | 29 |
| Message-ID: | <dc0s8t$sj4$1@sea.gmane.org> |
| References: | <20050724191302 DOT 58251D10DB AT rekin6 DOT o2 DOT pl> |
| Mime-Version: | 1.0 |
| User-Agent: | Mozilla Thunderbird 1.0.2 (Windows/20050317) |
| In-Reply-To: | <20050724191302.58251D10DB@rekin6.o2.pl> |
| X-IsSubscribed: | yes |
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/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |