小编AKA*_*KA4的帖子

How can i use a parameter as an inner array-name to my script?

When i write a script named array_call_self.sh as follows

#!/bin/bash
declare -A num word
word=(
 [a]='index_a'
 [b]='index_b'
 [c]='index_c'
)
num=(
 [a]=1
 [b]=2
 [c]=3
)
array=${$1[@]}
for i in ${$array[@]};do
  echo $i
done
Run Code Online (Sandbox Code Playgroud)

when i run bash array_call_self.sh word it return me

test.sh: line 13: ${$1[@]}: bad substitution
test.sh: line 14: ${$array[@]}: bad substitution
Run Code Online (Sandbox Code Playgroud)

bash variable associative-array

3
推荐指数
1
解决办法
120
查看次数

标签 统计

associative-array ×1

bash ×1

variable ×1