在下面的代码中,第二次插入到关联数组“originator”中,使第一次插入丢失。我检查第一个插入是否成功,但是当我将第二个关联项放入“发起者”时,第一项是空的,换句话说,它输出和空字符串。我不知道会发生什么。
declare -A originators
while read -r line
do
if [ "$count" -ge "2" ];
then
inner_count=0
#parse each line
if [ "$debug" = "1" ] ; then printf "%s\n" "$line" ; fi
for word in $line
do
if [ "$inner_count" = "1" ]; then tmp1="$word" ; fi
if [ "$inner_count" = "5" ]; then tmp1="$tmp1"" ---- ""$word" ;fi
inner_count=$((inner_count + 1))
done
originators=( ["$count"]="$tmp1" )
echo "$count ${originators["$count"]}"
fi
count=$((count + 1))
done < <(batctl tg)