${(P)…}: Parameter name indirection

${(P)name} interprets the value of name as further parameter name and then evaluates it.

Examples

Using parameter name indirection
1
2
3
4
5
6
declare -A data=([key]=value [key2]=value2)
name=data
# Prints array 'data'
echo ${(P)name}
# Prints value of `key2` or array `data`
echo ${${(P)name}[key2]}
Output:
1
2
value2 value
value2
BashSupport Pro is a Zsh IDE with support for ${(P)…}try it now!
© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal