Peng Yu
2018-02-22 04:57:09 UTC
Hi,
I have to assign "${!x[@]}" to an array and then extract the first
element. If I understand it correctly, this will involve an extra copy
which may be slow for large arrays. Is there a syntax that allows the
direct extraction of the first element of "${!x[@]}"? Thanks.
$ x=()
$ x[10]=a
$ x[2]=b
$ i=("${!x[@]}")
$ echo "${i[0]}"
2
I have to assign "${!x[@]}" to an array and then extract the first
element. If I understand it correctly, this will involve an extra copy
which may be slow for large arrays. Is there a syntax that allows the
direct extraction of the first element of "${!x[@]}"? Thanks.
$ x=()
$ x[10]=a
$ x[2]=b
$ i=("${!x[@]}")
$ echo "${i[0]}"
2
--
Regards,
Peng
Regards,
Peng