7.1.【定义数组】
• [test @test test]# declare [-afirx]
• 参数说明:
• -a :定义为数组 array
• -f :定义为函数 function
• -i :定义为整数 integer
• -r :定义为只读
• [root @test test]# declare -a myarry=(5 6 7 8)
• [root @test test]# echo ${myarry[2]}
• 显示结果为7
7.2.【为什么声明】
• [root @test test]# a=3
• [root @test test]# b=5
• [root @test test]# c=$a*$b
• [root @test test]# echo $c
• 3*5 <==糟糕!不是我们希望的结果,这是因为我们没有声明变量,变量缺省是字符类型,
所以$c就是字符串了,所以应该如下先声明
• [test @test test]# declare -i a=3
• [test @test test]# declare -i b=5
• [test @test test]# declare -i c=$a*$b
• [test @test test]# echo $c
• 15
7.3.【Shell脚本练习】
• 练习:写一个shell脚本declare.sh,要求输出:the result is==>3*6+20*3-30+28和the result is==>76
• 要求:使用变量
------------------------------------------------------------