日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Shell?$[]對整數進行數學運算實現_linux shell

作者:富士康質檢員張全蛋 ? 更新時間: 2023-03-01 編程語言

和 (())、let 命令類似,$[] 也只能進行整數運算。

Shell $[] 的用法如下:

$[表達式]

$[] 會對表達式進行計算,并取得計算結果。如果表達式中包含了變量,那么你可以加$,也可以不加。

Shell $[] 舉例:

[c.biancheng.net]$ echo $[3*5]  #直接輸出結算結果
15
[c.biancheng.net]$ echo $[(3+4)*5]  #使用()
35
[c.biancheng.net]$ n=6
[c.biancheng.net]$ m=$[n*2]  #將計算結果賦值給變量
[c.biancheng.net]$ echo $[m+n]
18
[c.biancheng.net]$ echo $[$m*$n]  #在變量前邊加$也是可以的
72
[c.biancheng.net]$ echo $[4*(m+n)]
72

需要注意的是,不能單獨使用 $[],必須能夠接收 $[] 的計算結果。例如,下面的用法是錯誤的:

[c.biancheng.net]$ $[3+4]
bash: 7: 未找到命令...
[c.biancheng.net]$ $[m+3]
bash: 15: 未找到命令...

原文鏈接:https://blog.csdn.net/qq_34556414/article/details/127423541

欄目分類
最近更新