我在bash中有一段这样的代码:
tencent=()
while read line
do
index=$(echo $line | awk '{printf "%s", $1}')
value=$(echo $line | awk '{printf "%s", $2}')
sindex="S_"$index
tencent[$sindex]=$value
done < $TENCENT_BILLS_MERGED
但之后我只得到这个数组中的一个元素,有人可以帮我解决吗?
答案 0 :(得分:2)
您需要声明关联数组而不是索引数组,因为您使用字符串/键作为索引。
使用整数引用索引数组(包括算术) 表达式)并且基于零;关联数组被引用 使用任意字符串。
使用declare -A name。
创建关联数组
因此;
tencent=()
应该是
declare -A tencent
答案 1 :(得分:1)