猫测试.sh
#!/bin/bash
key="index";
arr[$key]="val"
echo ${arr[${key}]}
/bin/bash-x test.sh
+ key=index
+ arr[$key]=val
+ echo val
val
然后我修改test.sh:
#!/bin/bash
key="index.index";
arr[$key]="val"
echo ${arr[${key}]}
/bin/bash -x test.sh
+ key=index.index
+ arr[$key]=val
test.sh: line 3: index.index: syntax error: invalid arithmetic operator (error token is ".index")
test.sh: line 4: index.index: syntax error: invalid arithmetic operator (error token is ".index")
为什么会出现此错误,任何建议将不胜感激!