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

Re: triviality regarding $# counts



Small followup I meant to type but didn't:

On Sat, Apr 13, 2024 at 1:19 PM Mark J. Reed <markjreed@xxxxxxxxx> wrote:

redline '\nddd=( "${(@f)aaa}" ) ... it seems like a lot of trouble to copy the array as it is.'


That comment confuses me; you aren't copying the array as it is at all! You've gone from aaa, which has one element, to ddd having 8 elements. That's a far cry from "copying as it is".

If you want to copy an array as it is, this is all you need:

fff=("${(@)aaa}")

Or, if you prefer the POSIX syntax:

fff=("${aaa[@]}")

After either of the above assignments, fff is an exact copy of aaa, including any empty elements. 

(If there aren't any empty elements or you want to strip them, you can use the even simpler fff=($aaa).)
--
Mark J. Reed <markjreed@xxxxxxxxx>


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