分页: 1 / 1

晕,得不了C的值。

发表于 : 2008-08-26 18:48
yuhongchun
学习中遇到到个问题:

a=1
b=2
c=$a+$b
declare -i c
echo $c

本来想得到3的,却不料总得到1+2,晕了。。。唉,求正解。

发表于 : 2008-08-26 18:57
BigSnake.NET
$((a+b))

发表于 : 2008-08-26 18:57
alinmn
let c=$a+$b

发表于 : 2008-08-26 18:59
yuhongchun
能用declare -i ; echo $c实现吗?

发表于 : 2008-08-26 18:59
yuhongchun
我也用别的方法实现了,但想用declare的方式实现。。。

发表于 : 2008-08-26 19:01
BigSnake.NET
先 declear -i c

发表于 : 2008-08-26 19:03
yuhongchun
恩,我试试先,thank you very much.

发表于 : 2008-08-26 19:06
yuhongchun
恩,确实,要先定义declare -i c,为什么呢???

发表于 : 2008-08-27 10:24
aBiNg

代码: 全选

declare

Declare variables and give them attributes.

      -i   The variable is to be treated as an integer; 
           arithmetic evaluation is performed when the 
           variable is assigned a value.