${(k)…}: Substitute array keys

For associative arrays, (k) substitutes array keys instead of values.

With subscripts, e.g. ${(k)array[value]}, it substitutes keys for associate arrays or indices for ordinary, indexed arrays.

Examples

Print keys of an associative array
1
2
declare -A data=([Joe]=4 [William]=3, [Jack]=2 [Averell]=1 )
echo "Dalton brothers: ${(k)data}"
Output:
1
Dalton brothers: William Joe Jack Averell
BashSupport Pro 是一款支持 k** 的 **Zsh 集成开发环境 - 立即试用
© 2020–2024 Joachim Ansorg
声明
隐私政策
许可条款