Does SCALE/Linux really have no bc nor dc for float calculations in bash?

I’m trying to “port” a bash script from CORE to SCALE. It seems SCALES version of Linux has no dc or bc program to work with bash scripts in doing float calculations. Dare I enable apt-get and add it?

I decided to also change the (rather complex) script from bash to zsh, which does float calculations without other utilities. A lot of unexpected changes are needed, but getting there.

1 Like

Is this complex script a PID fan controller per chance?

Yup it is

1 Like

BTW, I ported my script to scale, if it helps

1 Like

See NAS-115175 and NAS-121822

@stux, reading the history of your script reminded me of those heady days of 2016, when the grass was green and the world made sense. All of us probing our boards and figuring out raw commands and PID. As for the script, it doesn’t help me because my board has a single fan zone. Also I prefer the log format that my script makes (of course). And I’m sure perl is a very fine language, but I don’t speak a word of it. And I’m too lazy to climb that mountain to learn it.

@dak180, seems those issues haven’t gone anywhere for some reason. It would be such a simple thing to include those utilities. But I’m switching to zsh, which doesn’t require them to do floating arithmetic.

1 Like

I updated some older fan monitor scripts for Scale and ran into the same problem, but I fixed it by doing the calculations a different way that worked in Scale 22.12 (I’m about to update to Dragonfish).
Where you might have (in a bash script) :

Tmean=$(echo "scale=3; $Tsum / $i" | bc)

instead, do the following :

Tmean=$(awk "BEGIN { printf \"%.3f\", $Tsum / $i }")

another example, the original :

SEC=$(bc <<< "$T*60")

change to:

SEC=$(awk "BEGIN { print $T * 60 }")

I think that was all I needed to change, YMMV but hopefully you can work it out !

Thanks. That looks like my script you’re updating there! I considered awk but decided to go with zsh instead. The statements just look more readable and intuitive that way. Stuff like
D=$( printf "%.1f" $(( Kd * (ERRc-ERRp) / DRIVE_T )) )

I’ll confess the scripts came from links in discussions in the old forum (I think) - if the originals were yours, I’m very grateful, they saved me a lot of time and trouble getting my fans to work as I want them to (ref “those heady days of 2016” ) - much appreciated !