${(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.
Links
Examples
- Print keys of an associative array
- Output:
1 2declare -A data=([Joe]=4 [William]=3, [Jack]=2 [Averell]=1 ) echo "Dalton brothers: ${(k)data}"1Dalton brothers: William Joe Jack Averell
BashSupport Pro ist eine Zsh IDE mit Unterstützung für ${(k)…} - probieren Sie es jetzt aus!