Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Fri, 11 Apr 2003 13:00:37 -0700 (PDT) From: "Peter A. Castro" To: cygwin AT cygwin DOT com Subject: Re: bash and real arithmetic In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Fri, 11 Apr 2003, Igor Pechtchanski wrote: > On Fri, 11 Apr 2003, Randall R Schulz wrote: > > > At 10:21 2003-04-11, Igor Pechtchanski wrote: > > >On Sat, 12 Apr 2003, Stepan Yakovenko wrote: > > > > > > > HI! > > > > > > > > Is it possible to get for loops working > > > > in double arithmetic in bash ? I've got to run > > > > a program with a real argument many times, changing it > > > > every run by some fixed small (<1) number. > > > > Thanx in advance, sorry for my broken English. > > >Umm, scale? For example: > > > for (( i=0; i < 10; i++ )); do echo 0.$i; done > > Umm, leading zero suppression? > > % for (( i=0; i < 100; i++ )); do echo 0.$i; done > > 0.0 > > 0.1 > > [snip] > > 0.20 > > etc. > > Randall > > Yes, yes... It was an /example/. If you want leading zeros for numbers > greater than 10, use bash's "printf" builtin: > for (( i=0; i < 100; i++ )); do echo 0.$(printf "%02d" $i); done > Better? :-p > Igor zsh does integer math, but since you want fractional math, zsh won't do. You could simply use 'bc'. Eg: $ x='2.2' $ x=`echo $x+0.3 | bc` $ echo $x 2.5 -- Peter A. Castro or "Cats are just autistic Dogs" -- Dr. Tony Attwood -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/