Re: [Nolug] Lists in bash

From: Brett D. Estrade <estrabd_at_yahoo.com>
Date: Wed, 12 Feb 2003 16:19:46 -0800 (PST)
Message-ID: <20030213001946.20461.qmail@web41501.mail.yahoo.com>

FreeBSD comes with the "jot" utility that spits out numbers in many different orders and formats.
Check it out...

Brett

--- Ron Johnson <ron.l.johnson@cox.net> wrote:
> Ok, progress is being made!
>
> $ a=`ctr=0;ctr1=10;while [ "$ctr" != "$ctr1" ]; \
> do echo $ctr;let ctr+=1;done`
> $ echo $a
> 0 1 2 3 4 5 6 7 8 9
>
> Unfortunately, something still doesn't work:
>
> $ for i in $a; do echo $a; done
> 0 1 2 3 4 5 6 7 8 9
> 0 1 2 3 4 5 6 7 8 9
> 0 1 2 3 4 5 6 7 8 9
> 0 1 2 3 4 5 6 7 8 9
> 0 1 2 3 4 5 6 7 8 9
> 0 1 2 3 4 5 6 7 8 9
> 0 1 2 3 4 5 6 7 8 9
> 0 1 2 3 4 5 6 7 8 9
> 0 1 2 3 4 5 6 7 8 9
> 0 1 2 3 4 5 6 7 8 9
>
> $ for i in a; do echo $a; done
> 0 1 2 3 4 5 6 7 8 9
>
> $ a=(`ctr=0;ctr1=10;while [ "$ctr" != "$ctr1" ]; \
> do echo $ctr;let ctr+=1;done`)
> +0-
> +0-
> +0-
> +0-
> +0-
> +0-
> +0-
> +0-
> +0-
> +0-
>
> So how do I get to each element in the list?
>
> Would it be easier to do in perl?
>
>
> On Wed, 2003-02-12 at 16:51, John Kosta wrote:
> > Script:
> >
> > #!/bin/bash
> >
> > counter=0
> > countupto=11
> > while [ "$counter" != "$countupto" ]
> > do
> > echo $counter
> > let counter+=1
> > done
> >
> > Result:
> >
> > john@localhost:~$ bash test
> > 0
> > 1
> > 2
> > 3
> > 4
> > 5
> > 6
> > 7
> > 8
> > 9
> > 10
> >
> > You could set countupto however you want.
> >
> > --John
> >
> >
> > ----- Original Message -----
> > From: "Ron Johnson" <ron.l.johnson@cox.net>
> > To: "NOLUG ML" <nolug@joeykelly.net>
> > Sent: Wednesday, February 12, 2003 3:54 PM
> > Subject: Re: [Nolug] Lists in bash
> >
> >
> > > On Wed, 2003-02-12 at 13:05, Brett D. Estrade wrote:
> > > > #!/usr/local/bin/bash
> > > >
> > > > # define list - note parans
> > > > list=(1 2 3 4 5 6 7 8 9 10 11 12 13)
> > > >
> > > > # cycle through list - note array ref and "@"
> > > > # in the index spot
> > > >
> > > > for i in "${list[@]}"; do
> > > > echo $i
> > > > done
> > > >
> > > > #----end of script
> > >
> > > Thanks. However, what if I had an arbitrarily large number that I
> > > wanted in the list.
> > >
> > > Are you saying that there's no way to do nummeric sequences?
> > >
> > > > --- Ron Johnson <ron.l.johnson@cox.net> wrote:
> > > > > Hi,
> > > > >
> > > > > This, I know how to do:
> > > > > $ for i in 1 2 3 4 5 ; do echo $i ; done
> > > > > 1
> > > > > 2
> > > > > 3
> > > > > 4
> > > > > 5
> > > > >
> > > > > That's great, and reminds me of python. Is there a syntax for making
> > > > > arbitrarily long numerical lists, without having to enumerate each
> > > > > number?
> > > > >
> > > > > For example, these syntax attempts failed:
> > > > > $ for i in 1-5 ; do echo $i ; done
> > > > > 1-5
> > > > > $ for i in 1..5 ; do echo $i ; done
> > > > > 1..5
> > > > > $ for i in [1-5] ; do echo $i ; done
> > > > > [1-5]
> > > > >
>
> --
> +------------------------------------------------------------+
> | Ron Johnson, Jr. Home: ron.l.johnson@cox.net |
> | Jefferson, LA USA http://members.cox.net/ ron.l.johnson |
> | |
> | "For me and windows it became a matter of easy to start |
> | with, and becoming increasingly difficult to be produc- |
> | tive as time went on, and if something went wrong very |
> | difficult to fix, compared to linux's large over head |
> | setting up and learning the system with ease of use and |
> | the increase in productivity becoming larger the longer I |
> | use the system." |
> | Rohan Nicholls , The Netherlands |
> +------------------------------------------------------------+
>
> ___________________
> Nolug mailing list
> nolug@nolug.org

=====
I know who stole those lunches...it was that d@mn sasquatch!!!! -- "Billy Madison" (1995)

#! ~/myInfo
set url http://www.brettsbsd.net
set eFax (253)484-8755
#A.M.D.G
exit 0

__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com
___________________
Nolug mailing list
nolug@nolug.org
Received on 02/12/03

This archive was generated by hypermail 2.2.0 : 12/19/08 EST