How to add values in a variable in Unix shell scripting?

前端 未结 9 2016
谎友^
谎友^ 2021-02-19 02:14

I have two variables called count1 and count7

count7=0
count7=$(($count7 + $count1))

This shows an error \"expression is not complete; more tok

9条回答
  •  [愿得一人]
    2021-02-19 02:38

    I don't have a unix system under my hands, but try this:

    count7=$((${count7} + ${count1}))

    Or maybe you have a shell that doesn't support this expression. I think bash does support it, but sh doesn't.

    EDIT: There is another syntax, try:

    count7=`expr $count7 + $count1`
    

提交回复
热议问题