我正在尝试总结文本文件中的值
尝试.txt
firstNumber,1
secondNumber,2
我试过这个脚本
#!/bin/bash
while IFS, read -r -a array; do
printf "%s %s\n" "${array[0]} ${array[1]}"
for n in "${array[1]}"; do
((total += n))
echo "total =" $total
done
done < try.txt
我得到了这个输出
firstNumber 1
total = 1
secondNumber 2
total = 3
预期产出
firstNumber 1
secondNumber 2
total = 3
提前致谢