[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash doubt



On 13/05/2008, L. V. Gandhi <lvgandhi@gmail.com> wrote:
> I have a script as follows
[snip]
>                 i=$i+1
[snip]
>  How to correct it

Your counter is wrong. $i + 1 means to treat i as a string and to
append the string "1" to it. If you want to do arithmetic in bash, you
have to put it inside brackets. i = $[i+1].

Btw, an easier way to do a for loop of this sort in bash is to do "for
i in `seq 20`" (notice the backticks).

If you want to do a lot of text manipulation, it may feel more natural
to use Perl (or at least it feels more natural to me).

- Jordi G. H.


Reply to: