早教吧 育儿知识 作业答案 考试题库 百科 知识分享

linux小数点如何相加/bin/shus=`top-n1|awk'{print$2}'|sed-n3p|sed's/%//g'`sy=`top-n1|awk'{print$4}'|sed-n3p|sed's/%//g'`total=`expr$us+$sy`出错提示expr:non-numericargumentecho$us>/will/us.txtecho$sy>/will/s

题目详情
linux 小数点如何相加
/bin/sh
us=`top -n 1 | awk '{print $2}' |sed -n 3p | sed 's/%//g'`
sy=`top -n 1 | awk '{print $4}' |sed -n 3p | sed 's/%//g'`
total=`expr $us + $sy`出错提示expr:non-numeric argument
echo $us > /will/us.txt
echo $sy > /will/sy.txt
echo $total > total.txt
▼优质解答
答案和解析
shell不可直接进行小数运算,可以用去其他方法,这是我想到的1:用bc方法,你可以去查查echo $us+$sy | bc如我的结果# echo $a8.8# echo $b9.1# echo $a+$b | bc17.92:用awk方法# awk -v a=$a -v b=$b 'BEGIN{print a+...