bash arithmetic expressions with variables

前端 未结 2 721
孤城傲影
孤城傲影 2020-12-21 22:25

I am having troubles with the arithmetic expressions in a bash file (a unix file .sh).

I have the variable \"total\", which consists of a few numbers separated by sp

2条回答
  •  醉梦人生
    2020-12-21 23:21

    Wrap arithmetic operations within ((...)):

    dollar=0
    for a in $total; do
      ((dollar += a))
    done
    

提交回复
热议问题