【linux系统编程基础知识-Shell脚本学习笔记7-数组】

13 篇文章 0 订阅

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
• 要求:使用变量

------------------------------------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值