Unix Technical Forum

bash doubt

This is a discussion on bash doubt within the Debian Linux Users forum forums, part of the Debian Linux category; --> On Tue, May 13, 2008 at 08:05:16PM -0500, Jordi Gutiérrez Hermoso wrote: > On 13/05/2008, L. V. Gandhi <lvgandhi@gmail.com> ...


Go Back   Unix Technical Forum > Unix Operating Systems > Debian Linux > Debian Linux Users forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 05-24-2008, 06:04 AM
Osamu Aoki
 
Posts: n/a
Default Re: bash doubt

On Tue, May 13, 2008 at 08:05:16PM -0500, Jordi Gutiérrez Hermoso wrote:
> 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].


Although it should work.... why not use POSIX style which bas accept
too.

i=$((i+1))


For speed of shell script, it is faster to use dash and better to be
portable.

> 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).


Yep. I agree.

Also with xargs command instead of shell loop, you should get faster
script.

> 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).


True.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:19 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com