Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: shuffle array
Stephane Chazelas wrote on Sun, Dec 01, 2019 at 20:07:19 +0000:
> array=("${(0@)$(printf '%s\0' "$array[@]" | shuf -z)[1,-2]}")
>
> But that would still not work for array elements containing
> NULs.
I think the following would work? —
typeset -a l=(…)
eval "l=(" $(print -rl -- "${(@qqqq)l}" | shuf) ")"
shuf(1) expects newline-separated output, and the output of ${(qqqq)} never
has literal newlines.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author