From 00db11a8386e786389c0e2d43cfaadc54007c9bb Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 13 Mar 2024 22:13:20 +0200 Subject: Remove one decimal point from output --- .config/polybar/scripts/temperature.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.config/polybar/scripts/temperature.sh b/.config/polybar/scripts/temperature.sh index 10c8ddc..7ef6abb 100755 --- a/.config/polybar/scripts/temperature.sh +++ b/.config/polybar/scripts/temperature.sh @@ -2,11 +2,17 @@ # Pulls CPU temps, averages them, and outputs them -let count=0 +count=0 sum=0.0 -for temp in $(sensors | grep "^Core" | grep -e '+.*C' | cut -f 2 -d '+' | cut -f 1 -d ' ' | sed 's/°C//'); do - sum=$(echo $sum+$temp | bc) - let count+=1 + +# Iterate over each temperature reading +for temp in "$(sensors | grep "^Core" | grep -e '+.*C' | cut -f 2 -d '+' | cut -f 1 -d ' ' | sed 's/°C//')"; do + sum=$(echo "$sum + $temp" | bc) + ((count++)) done -avg=$(qalc -t $sum/$count) -echo "${avg}°C" + +# Calculate the average +avg=$(echo "scale=0; $sum / $count" | bc) + +# Output the average temperature without decimal points +echo " ${avg%.*}°C" -- cgit v1.2.3