ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [20201109]bash shell特殊算术方式.txt

[20201109]bash shell特殊算术方式.txt

原创 Linux操作系统 作者:lfree 时间:2020-11-09 09:24:31 0 删除 编辑

[20201109]bash shell特殊算术方式.txt

--//有时候工作需要写bash shell脚本,一般使用bash进行算术计算,我以前写过一个链接:
--//http://blog.itpub.net/267265/viewspace-2286893/ =>[20181229]bash shell的算术运算 .txt
--//我忽略一种特殊情况,可以直接写表达式,这样更加简单直观。通过例子说明:

declare -i i
i=13+3*4
echo $i

$ declare -i i
$ i=13+3*4
$ echo $i
25

--//只要开始使用declare定义变量i是整形,就可以直接计算。

$ i=13 +3*4
-bash: +3*4: command not found

--//缺点不能有空格。

$ a=12
$ b=14

$ i=$a+$b
$ echo $i
26

--//补充一点使用typeset -i等同于declare -i.




来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2732892/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969562