shell脚本运算例子

#!/bin/bash
#shell脚本进行运算的一个例子
while [ 1 ]
do
cpu_tmp=`i2cget -f -y 4 0x50 0x05`
#用let 命令进行cpu_tmp-50运算
let cpu_tmp-=50
echo "cpu temperature:${cpu_tmp}"
volstr=`i2ctransfer -f -y 4 w1@0x50 0x06 r12`
echo "voltage:${volstr}"
v1=`i2cget -f -y 4 0x50 0x06`
v2=`i2cget -f -y 4 0x50 0x07`
#用let命令进行移位和或运算
let v3="($v2<<8)|$v1"
#v3除100浮点运算,结果保留3位小数
P2V5=`echo "scale=3;${v3}/100.0"|bc`
echo "P2V5 voltage:$P2V5"
bmc_str=`i2ctransfer -f -y 4 w1@0x50 0x20 r13`
echo "bmcInfo:${bmc_str}"
str=`lsblk | grep nvme`
if [ -z "$str" ]
then
echo "nvme is lost!"
fi
exit 0
sleep 1
done
 

你可能感兴趣的:(linux开发,开发语言)