Shell脚本数学运算

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shell脚本数学运算相关的知识,希望对你有一定的参考价值。

直接上代码。

#!/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}"

 

以上是关于Shell脚本数学运算的主要内容,如果未能解决你的问题,请参考以下文章