首页 > 代码库 > Shell脚本(二)数学运算

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脚本(二)数学运算