星期三, 五月 30, 2007

bash number

sh$ i=0
sh$ i++
-bash: i++: command not found
sh$ (j=0)
sh$ echo $j
# 空
sh$ ((k=0))
sh$ echo $k
0
sh$ ((k = 0))
# 注意等号两边有空格
sh$ echo $k
0
sh$ (k++)
-bash: k++: command not found
sh$ ((k++))
sh$ echo $k
1

sh$ i=5
sh$ ((k = $i))
sh$ echo $k
5

没有评论: