* I've forgotten again how to do this --> 0-100
@ 1998-01-15 0:12 Timothy J Luoma
1998-01-15 0:46 ` Danek Duvall
1998-01-15 10:28 ` Andrew Main
0 siblings, 2 replies; 13+ messages in thread
From: Timothy J Luoma @ 1998-01-15 0:12 UTC (permalink / raw)
To: zsh-users
I know this is dumb, and I know I've asked before, and I know I should be
able to figure it out.
Ignorance, expressed, I'll still ask:
if I want to make a loop to go from 0 to 100, how do I do that?
for i in 0-100; do
echo $i
done
but the "0-100" part is the part I can never remember....
TjL, Class Dunderhead
ps -- what is this actually called, so I can possibly find it in the man pages ?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: I've forgotten again how to do this --> 0-100
1998-01-15 0:12 I've forgotten again how to do this --> 0-100 Timothy J Luoma
@ 1998-01-15 0:46 ` Danek Duvall
1998-01-15 1:03 ` Mirar
1998-01-15 10:28 ` Andrew Main
1 sibling, 1 reply; 13+ messages in thread
From: Danek Duvall @ 1998-01-15 0:46 UTC (permalink / raw)
To: zsh-users
> if I want to make a loop to go from 0 to 100, how do I do that?
>
> for i in 0-100; do
> echo $i
> done
for i in {0..100}; do
echo $i
done
> ps -- what is this actually called, so I can possibly find it in the man pages ?
brace expansion, I believe.
Danek
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: I've forgotten again how to do this --> 0-100
1998-01-15 0:46 ` Danek Duvall
@ 1998-01-15 1:03 ` Mirar
0 siblings, 0 replies; 13+ messages in thread
From: Mirar @ 1998-01-15 1:03 UTC (permalink / raw)
To: Danek Duvall; +Cc: zsh-users
> > ps -- what is this actually called, so I can possibly find it in the man pages ?
>
> brace expansion, I believe.
What it really does is expading "{0..100}" to "0 1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", so
for i in {0..100}; ...
is the same as
for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
93 94 95 96 97 98 99 100; ...
/Mirar
__________________________________________________________________________
Idonex AB Telefon Telefax nalle
Skolgatan 10 013-376814 013-376801 0708-376867
582 34 Linköping mirar@idonex.se http://www.idonex.se/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: I've forgotten again how to do this --> 0-100
1998-01-15 0:12 I've forgotten again how to do this --> 0-100 Timothy J Luoma
1998-01-15 0:46 ` Danek Duvall
@ 1998-01-15 10:28 ` Andrew Main
1998-01-15 15:01 ` Geoff Wing
` (3 more replies)
1 sibling, 4 replies; 13+ messages in thread
From: Andrew Main @ 1998-01-15 10:28 UTC (permalink / raw)
To: Timothy J Luoma; +Cc: zsh-users
Timothy J Luoma wrote:
>for i in 0-100; do
> echo $i
>done
for ((i=0;i<=100;i++)); do
echo $i
done
takes less memory than the brace expansion method.
-zefram
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: I've forgotten again how to do this --> 0-100
1998-01-15 10:28 ` Andrew Main
@ 1998-01-15 15:01 ` Geoff Wing
1998-01-15 17:39 ` Brandon C. George
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: Geoff Wing @ 1998-01-15 15:01 UTC (permalink / raw)
To: zsh-users
Andrew Main <zefram@tao.co.uk> typed:
:Timothy J Luoma wrote:
:>for i in 0-100; do
:> echo $i
:>done
:for ((i=0;i<=100;i++)); do
: echo $i
:done
:takes less memory than the brace expansion method.
And is only available in zsh-3.1.2 up. Or maybe 3.1.1 up (but it's not one
of the 30 odd zsh versions I've got in my bin dir).
--
Geoff Wing [gcw@pobox.com] Phone : +61-3-9818 2977
Technical Manager: PrimeNet Computer Consultants Facsimile: +61-3-9818 5155
Work URL: http://www.primenet.com.au/ Mobile : 0412 162 441
Ego URL: http://pobox.com/~gcw/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: I've forgotten again how to do this --> 0-100
1998-01-15 10:28 ` Andrew Main
1998-01-15 15:01 ` Geoff Wing
@ 1998-01-15 17:39 ` Brandon C. George
1998-01-15 17:51 ` Andrew Main
1998-01-15 20:32 ` Sweth Chandramouli
1998-01-22 3:54 ` related question Sweth Chandramouli
3 siblings, 1 reply; 13+ messages in thread
From: Brandon C. George @ 1998-01-15 17:39 UTC (permalink / raw)
To: Andrew Main; +Cc: zsh-users
On Thu, Jan 15, 1998 at 10:28:37AM +0000, Andrew Main wrote:
> Timothy J Luoma wrote:
> >for i in 0-100; do
> > echo $i
> >done
>
> for ((i=0;i<=100;i++)); do
> echo $i
> done
>
> takes less memory than the brace expansion method.
>
> -zefram
Is there a switch I need to do something like this?
> atc1:~> for ((i=0;i<=100;i++)); do
> zsh: parse error near `((i=0'
-brandon
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: I've forgotten again how to do this --> 0-100
1998-01-15 17:39 ` Brandon C. George
@ 1998-01-15 17:51 ` Andrew Main
0 siblings, 0 replies; 13+ messages in thread
From: Andrew Main @ 1998-01-15 17:51 UTC (permalink / raw)
To: Brandon C. George; +Cc: zefram, zsh-users
Brandon C. George wrote:
>Is there a switch I need to do something like this?
You need zsh-3.1.something. On earlier versions you can still do
integer i=0
while ((i<=100)); do
echo $i
((i++))
done
-zefram
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: I've forgotten again how to do this --> 0-100
1998-01-15 10:28 ` Andrew Main
1998-01-15 15:01 ` Geoff Wing
1998-01-15 17:39 ` Brandon C. George
@ 1998-01-15 20:32 ` Sweth Chandramouli
1998-01-15 22:59 ` Geoff Wing
1998-01-22 3:54 ` related question Sweth Chandramouli
3 siblings, 1 reply; 13+ messages in thread
From: Sweth Chandramouli @ 1998-01-15 20:32 UTC (permalink / raw)
To: Andrew Main; +Cc: Timothy J Luoma, zsh-users
On Thu, Jan 15, 1998 at 10:28:37AM +0000, Andrew Main wrote:
> Timothy J Luoma wrote:
> >for i in 0-100; do
> > echo $i
> >done
>
> for ((i=0;i<=100;i++)); do
> echo $i
> done
>
> takes less memory than the brace expansion method.
how does it compare (memory-wise) to the following:
while (( $i < 101 )); do
echo $i
i=$((i+1))
done
(the brace expansion method makes the most sense to me, intuitively, followed by
the version i used above; the syntax of your for statement, however, always
confuses me.)
--
"Countin' on a remedy I've counted on before
Goin' with a cure that's never failed me
What you call the disease
I call the remedy" -- The Mighty Mighty Bosstones
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: I've forgotten again how to do this --> 0-100
1998-01-15 20:32 ` Sweth Chandramouli
@ 1998-01-15 22:59 ` Geoff Wing
1998-01-21 16:26 ` loops and all that Sven Guckes
0 siblings, 1 reply; 13+ messages in thread
From: Geoff Wing @ 1998-01-15 22:59 UTC (permalink / raw)
To: zsh-users
Sweth Chandramouli <sweth@astaroth.nit.gwu.edu> typed:
:On Thu, Jan 15, 1998 at 10:28:37AM +0000, Andrew Main wrote:
:> Timothy J Luoma wrote:
:> >for i in 0-100; do
:> > echo $i
:> >done
:> for ((i=0;i<=100;i++)); do
:> echo $i
:> done
:> takes less memory than the brace expansion method.
:how does it compare (memory-wise) to the following:
:while (( $i < 101 )); do
: echo $i
: i=$((i+1))
let i++
:done
--
Geoff Wing [gcw@pobox.com] Phone : +61-3-9818 2977
Technical Manager: PrimeNet Computer Consultants Facsimile: +61-3-9818 5155
Work URL: http://www.primenet.com.au/ Mobile : 0412 162 441
Ego URL: http://pobox.com/~gcw/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: loops and all that
1998-01-15 22:59 ` Geoff Wing
@ 1998-01-21 16:26 ` Sven Guckes
0 siblings, 0 replies; 13+ messages in thread
From: Sven Guckes @ 1998-01-21 16:26 UTC (permalink / raw)
To: ZShell Users
FYI:
I have added the tips on "iterative loops"
(brace expansion etc) to my page about
"ZShell Tips":
http://www.math.fu-berlin.de/~guckes/zsh/tips.html
If you have more stuff - send it!
Sven
--
Sven Guckes guckes@math.fu-berlin.de using zsh-3.0.5 [released 961218]
ZSH http://www.math.fu-berlin.de/~guckes/zsh/ Tips and tricks
ZSH http://www.peak.org/zsh/ Z shell home page [971022]
^ permalink raw reply [flat|nested] 13+ messages in thread
* related question
1998-01-15 10:28 ` Andrew Main
` (2 preceding siblings ...)
1998-01-15 20:32 ` Sweth Chandramouli
@ 1998-01-22 3:54 ` Sweth Chandramouli
1998-01-22 9:24 ` Bernd Eggink
1998-01-22 13:00 ` Mirar
3 siblings, 2 replies; 13+ messages in thread
From: Sweth Chandramouli @ 1998-01-22 3:54 UTC (permalink / raw)
To: zsh-users
On Thu, Jan 15, 1998 at 10:28:37AM +0000, Andrew Main wrote:
> for ((i=0;i<=100;i++)); do
> echo $i
> done
i've got a similar loop (just converted to this new for format, which
i'm trying to get used to using), to set the values in an array:
while read line ; do
for ((i=1;i<=11;i++)) ; do
field[$i]=`echo $line | cut -d';' -f$i | tr -d '"'`
done
done < in.file
this should take a line of the format
"foo1";"foo2";"foo3"; [...] ;"foo11"
and stuff each foo# into the appropriate spot in the array named field.
my question is, how do i then concatenate all of these values back into one
line? what i'm currently doing, since the max value for i is so small, is just
echo
"\"$field[1]\";\"$field[2]\";\"$field[3]\";\"$field[4]\";\"$field[5]\";\"$field[
6]\";\"$field[7]\";\"$field[8]\";\"$field[9]\";\"$field[10]\";\"$field[11]\""
pretty soon, however, i'm going to have to use this script on a larger set of
data, with a lot more fields per line; i don't want to have to type out each
item of the array individually. i know there's an easier way to do it, but it's
late, and my brain isn't working very well.
any suggestions (other than using perl, which is what all of my
coworkers say to do)?
tia,
sweth.
--
"Countin' on a remedy I've counted on before
Goin' with a cure that's never failed me
What you call the disease
I call the remedy" -- The Mighty Mighty Bosstones
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: related question
1998-01-22 3:54 ` related question Sweth Chandramouli
@ 1998-01-22 9:24 ` Bernd Eggink
1998-01-22 13:00 ` Mirar
1 sibling, 0 replies; 13+ messages in thread
From: Bernd Eggink @ 1998-01-22 9:24 UTC (permalink / raw)
To: Sweth Chandramouli; +Cc: zsh-users
Sweth Chandramouli wrote:
>
> while read line ; do
> for ((i=1;i<=11;i++)) ; do
> field[$i]=`echo $line | cut -d';' -f$i | tr -d '"'`
> done
> done < in.file
>
> this should take a line of the format
>
> "foo1";"foo2";"foo3"; [...] ;"foo11"
>
> and stuff each foo# into the appropriate spot in the array named field.
You don't need cut and tr, zsh can do all that:
while read line
do field=(${(s(;))line}) # split at ;
field=${field#?} # remove leading quotes
field=${field%?} # remove trailing quotes
done
> my question is, how do i then concatenate all of these values back into one
> line? what i'm currently doing, since the max value for i is so small, is just
>
> echo
> "\"$field[1]\";\"$field[2]\";\"$field[3]\";\"$field[4]\";\"$field[5]\";\"$field[
> 6]\";\"$field[7]\";\"$field[8]\";\"$field[9]\";\"$field[10]\";\"$field[11]\""
>
> pretty soon, however, i'm going to have to use this script on a larger set of
> data, with a lot more fields per line; i don't want to have to type out each
> item of the array individually. i know there's an easier way to do it, but it's
> late, and my brain isn't working very well.
>
> any suggestions (other than using perl, which is what all of my
> coworkers say to do)?
for ((i=1; i<=$#field; ++i))
do
field[i]="\"$field[i]\"" # restore quotes
done
line=${(j(;))field} # join elements using ;
Hope that helps!
--
Bernd Eggink
Regionales Rechenzentrum der Universitaet Hamburg
eggink@rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: related question
1998-01-22 3:54 ` related question Sweth Chandramouli
1998-01-22 9:24 ` Bernd Eggink
@ 1998-01-22 13:00 ` Mirar
1 sibling, 0 replies; 13+ messages in thread
From: Mirar @ 1998-01-22 13:00 UTC (permalink / raw)
To: Sweth Chandramouli; +Cc: zsh-users
> my question is, how do i then concatenate all of these values back into one
> line? what i'm currently doing, since the max value for i is so small, is just
print -n \"$field[17]\"
/Mirar
__________________________________________________________________________
Idonex AB Telefon Telefax nalle
Skolgatan 10 013-376814 013-376801 0708-376867
582 35 Linköping mirar@idonex.se http://www.idonex.se/
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~1998-01-22 13:19 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-15 0:12 I've forgotten again how to do this --> 0-100 Timothy J Luoma
1998-01-15 0:46 ` Danek Duvall
1998-01-15 1:03 ` Mirar
1998-01-15 10:28 ` Andrew Main
1998-01-15 15:01 ` Geoff Wing
1998-01-15 17:39 ` Brandon C. George
1998-01-15 17:51 ` Andrew Main
1998-01-15 20:32 ` Sweth Chandramouli
1998-01-15 22:59 ` Geoff Wing
1998-01-21 16:26 ` loops and all that Sven Guckes
1998-01-22 3:54 ` related question Sweth Chandramouli
1998-01-22 9:24 ` Bernd Eggink
1998-01-22 13:00 ` Mirar
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).