您的位置:首页 > 运维架构 > Shell

Shell脚本(二)数学运算

2017-07-22 21:32 423 查看
直接上代码。

#!/bin/bash

no1=4
no2=5

echo "using let ..."
let result=no1+no2
echo "result is: ${result}"

let result++
echo "result after 1 increment is: ${result}"

let result+=6
echo "result after 6 increment is: ${result}"

echo "using []..."
result=$[ no1 + no2 ]
echo "result is: ${result}"

echo "using (())..."
result=$(( no1 + no2 + 1 ))
echo "result is: ${result}"

echo "using expr ..."
result=$( expr $no1 + $no2 + 2 )
echo "result is: ${result}"

# ``等价于$()
echo "using \`\` ..."
result=`expr $no1 + $no2 + 3`
echo "result is: ${result}"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: