Skip to main content
rewording
Source Link
manatwork
  • 32.1k
  • 8
  • 104
  • 93

${!b[*]} expands to the indices used in array b.

What you would like has to be done in two steps, so eval will help: eval echo \${$b[*]}. (Note the \ which ensures that the first $ will pass the first step, the variable expansion, and will be only expanded in the second step by eval.)

Regarding your interpretation of the Bash manual, sounds like you got it wrong. According to Parameter Expansion ! is both used for indirect expansion ({!a}), Names matching prefix (${!a*}) and List of array keys, but you intention is variable dereferencing (${!a[*]}). Because List of array keys has the same syntax as your intended indirect expansion+array element expansion, whichthe later is not supported by Bashas is.

${!b[*]} expands to the indices used in array b.

What you would like has to be done in two steps, so eval will help: eval echo \${$b[*]}. (Note the \ which ensures that the first $ will pass the first step, the variable expansion, and will be only expanded in the second step by eval.)

Regarding your interpretation of the Bash manual, sounds like you got it wrong. According to Parameter Expansion ! is used for Names matching prefix and List of array keys, but you intention is variable dereferencing, which is not supported by Bash.

${!b[*]} expands to the indices used in array b.

What you would like has to be done in two steps, so eval will help: eval echo \${$b[*]}. (Note the \ which ensures that the first $ will pass the first step, the variable expansion, and will be only expanded in the second step by eval.)

According to Parameter Expansion ! is both used for indirect expansion ({!a}), Names matching prefix (${!a*}) and List of array keys (${!a[*]}). Because List of array keys has the same syntax as your intended indirect expansion+array element expansion, the later is not supported as is.

Source Link
manatwork
  • 32.1k
  • 8
  • 104
  • 93

${!b[*]} expands to the indices used in array b.

What you would like has to be done in two steps, so eval will help: eval echo \${$b[*]}. (Note the \ which ensures that the first $ will pass the first step, the variable expansion, and will be only expanded in the second step by eval.)

Regarding your interpretation of the Bash manual, sounds like you got it wrong. According to Parameter Expansion ! is used for Names matching prefix and List of array keys, but you intention is variable dereferencing, which is not supported by Bash.