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

前端 未结 9 2011
谎友^
谎友^ 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:56

    the above script may not run in ksh. you have to use the 'let' opparand to assing the value and then echo it.

    val1=4
    
    val2=3
    
    let val3=$val1+$val2
    
    echo $val3 
    
    0 讨论(0)
  • 2021-02-19 02:56
     echo "$x"
        x=10
        echo "$y"`enter code here`
        y=10
        echo $[$x+$y]
    

    Answer: 20

    0 讨论(0)
  • 2021-02-19 03:03
    var=$((count7 + count1))
    

    Arithmetic in bash uses $((...)) syntax.

    You do not need to $ symbol within the $(( ))

    0 讨论(0)
提交回复
热议问题