سؤال

I have this line in bash,

cpu=`top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print $1}'

Thats working as I want it if I echo it but when used in the next line as part of a equation.

joulesFinal=$(($joules2*$cpu))

I get the error from system

arithmetic expression: expecting EOF: "6*93.4"

Help appreciated!

هل كانت مفيدة؟

المحلول

Bash arithmetic is integer only. It won't accept fractional numbers like 93.4. You need to pipe the expression through bc.

joulesFinal=`echo $joules2 * $cpu | bc`
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top