Replace bc commands
Some systems may not support the bc command. Replace
with an alterative that performs simple floating-
point arithmetic.
Signed-off-by: Lisa Nguyen <lisa.nguyen@linaro.org>
diff --git a/cpufreq/cpufreq_06.sh b/cpufreq/cpufreq_06.sh
index 87b2c73..b86db34 100755
--- a/cpufreq/cpufreq_06.sh
+++ b/cpufreq/cpufreq_06.sh
@@ -42,7 +42,7 @@
return 1
fi
- value=$(echo "scale=3;($result / $freq)" | bc -l)
+ value=$(echo $result $freq | awk '{ printf "%.3f", $1 / $2 }')
eval $freq_results_array$index=$value
eval export $freq_results_array$index
index=$((index + 1))
@@ -53,7 +53,7 @@
sum=0
res=$(eval echo \$$freq_results_array$index)
- sum=$(echo "($sum + $res)" | bc -l)
+ sum=$(echo $sum $res | awk '{ printf "%f", $1 + $2 }')
index=$((index + 1))
}
@@ -63,14 +63,14 @@
res=$(eval echo \$$freq_results_array$index)
# compute deviation
- dev=$(echo "scale=3;((( $res - $avg ) / $avg) * 100 )" | bc -l)
+ dev=$(echo $res $avg | awk '{printf "%.3f", (($1 - $2) / $2) * 100}')
# change to absolute
dev=$(echo $dev | awk '{ print ($1 >= 0) ? $1 : 0 - $1}')
index=$((index + 1))
- res=$(echo "($dev > 5.0)" | bc -l)
+ res=$(echo $dev | awk '{printf "%f", ($dev > 5.0)}')
if [ "$res" = "1" ]; then
return 1
fi
@@ -97,7 +97,7 @@
for_each_frequency $cpu compute_freq_ratio_sum
- avg=$(echo "scale=3;($sum / $index)" | bc -l)
+ avg=$(echo $sum $index | awk '{ printf "%.3f", $1 / $2}')
for_each_frequency $cpu check_freq_deviation
}
diff --git a/include/functions.sh b/include/functions.sh
index 518f555..bb71302 100644
--- a/include/functions.sh
+++ b/include/functions.sh
@@ -188,16 +188,16 @@
frequnit() {
freq=$1
- ghz=$(echo "scale=1;($freq / 1000000)" | bc -l)
- mhz=$(echo "scale=1;($freq / 1000)" | bc -l)
+ ghz=$(echo $freq | awk '{printf "%.1f", ($1 / 1000000)}')
+ mhz=$(echo $freq | awk '{printf "%.1f", ($1 / 1000)}')
- ghz_value=$(echo "($ghz > 1.0)" | bc -l)
+ ghz_value=$(echo $ghz | awk '{printf "%f", ($1 > 1.0)}')
if [ "$ghz_value" = "1" ]; then
echo $ghz GHz
return 0
fi
- mhz_value=$(echo "($mhz > 1.0)" | bc -l)
+ mhz_value=$(echo $mhz | awk '{printf "%f", ($1 > 1.0)}')
if [ "$mhz_value" = "1" ];then
echo $mhz MHz
return 0