Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: shuffle array



Marc Chantreux wrote:

>>> print -l $array |shuff|read -A array
>>
>> The first two steps work, but the result
>> array seems to have only one element?
>
> those filters shuffle lines so you need to
> print 1 element per line (-l).
>
> can you show us examples?

$ local -a arg_array
$ arg_array=(1 2 3 a b c)
$ print -l $arg_array | shuf
3
b
2
c
a
1

works!

$ local -a arg_array
$ arg_array=(1 2 3 a b c)
$ print -l $arg_array | shuf | read -A new_array
$ echo $new_array
1

doesn't work, just one element...

$ echo $#new_array
1
$ echo $#arg_array
6

...

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Messages sorted by: Reverse Date, Date, Thread, Author