* selecting elements in array
@ 2005-04-21 3:43 Wataru Kagawa
2005-04-21 6:06 ` Eric Mangold
0 siblings, 1 reply; 3+ messages in thread
From: Wataru Kagawa @ 2005-04-21 3:43 UTC (permalink / raw)
To: zsh-users
Hi all,
How do I select elements with indices that are multiples of 3, in an
array? For example, I have,
list=( 123 native Terminal 456 native Excel 789 native X11 )
and would like to select,
Terminal Excel X11
for compadd. Help is much appreciated.
Wataru Kagawa
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: selecting elements in array
2005-04-21 3:43 selecting elements in array Wataru Kagawa
@ 2005-04-21 6:06 ` Eric Mangold
2005-04-21 7:34 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Eric Mangold @ 2005-04-21 6:06 UTC (permalink / raw)
To: Wataru Kagawa, zsh-users
On Thu, 21 Apr 2005 13:43:55 +1000, Wataru Kagawa
<wkagawa@jota.gsc.riken.go.jp> wrote:
> Hi all,
>
> How do I select elements with indices that are multiples of 3, in an
> array? For example, I have,
>
> list=( 123 native Terminal 456 native Excel 789 native X11 )
>
> and would like to select,
>
> Terminal Excel X11
for i in {1..3}; do
print $list[$(($i*3))]
done
or build a new array:
new=()
for i in {1..3}; do
new+=( $list[$(($i*3))] )
done
-Eric
>
> for compadd. Help is much appreciated.
>
> Wataru Kagawa
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: selecting elements in array
2005-04-21 6:06 ` Eric Mangold
@ 2005-04-21 7:34 ` Bart Schaefer
0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2005-04-21 7:34 UTC (permalink / raw)
To: zsh-users
On Apr 21, 4:06pm, Eric Mangold wrote:
} Subject: Re: selecting elements in array
}
} On Thu, 21 Apr 2005 13:43:55 +1000, Wataru Kagawa
} <wkagawa@jota.gsc.riken.go.jp> wrote:
}
} > How do I select elements with indices that are multiples of 3, in an
} > array? [...] for compadd. Help is much appreciated.
}
} for i in {1..3}; do
} print $list[$(($i*3))]
} done
Right, except replace "print" with "compadd", and you don't need the
$(( )) because the stuff in the [ ] is already treated as arithmetic.
for i in {1..3}; do compadd $list[i*3]; done
or
for ((i=3; $+list[i]; i+=3)); do compadd $list[i]; done
or any of a number of other ways. There's not, however, a way to write
a single subscript parameter expansion that picks out non-contiguous
array slices.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-04-21 7:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-21 3:43 selecting elements in array Wataru Kagawa
2005-04-21 6:06 ` Eric Mangold
2005-04-21 7:34 ` Bart Schaefer
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).