Doubts about shell type declaration

topic description

z@z:~/www/z/test/shell$ a=11
z@z:~/www/z/test/shell$ b=22
z@z:~/www/z/test/shell$ c=$a+$b
z@z:~/www/z/test/shell$ echo $c
11+22

because shell variables are all string types by default, it is understandable that the value of variable c is 11cm 22.

then the problem arises. I declare c as an integer with declare, and the output c value is still 11-22

.
z@z:~/www/z/test/shell$ declare -i c
z@z:~/www/z/test/shell$ echo $c
11+22

declares an integer, why is the value of c still a string?

Dec.11,2021

shell doesn't seem to cast, but if you do it again, it's the desired result

  

you can get the desired results with the let command
let c=$a+$b
echo $c

Menu