Tiny Core Linux
Tiny Core Base => Raspberry Pi => Topic started by: gavinmc42 on October 29, 2014, 11:17:03 PM
-
Trying to do floating point in ash shell scripts.
Is there anything like the bc command line calculator in the tcz?
-
Hi gavinmc42
There is a calc script in /usr/bin/ that utilizes awk. Try entering this at the command line:
calc 'sqrt(2)'
-
Hi gavinmc42
Just realized this is RPi and I don't know if calc is included. Here are the contents of the script:
#!/bin/sh
if [ -z ${1} ]; then
echo
echo " -=[ Simple Awk Calculator ]=-"
echo "Put formula in quotes (single or double) examples:"
echo "calc '3*4'"
echo "calc 'sqrt(9)'"
exit 0
fi
awk "BEGIN{ print $* }"
-
Thanks,
Typed calc into terminal and something came up, so it's there
Yep does floating point, yippee.
-
This helps with getting syntax correct
http://homepage.eircom.net/~nigelbrooke/Electronics_Projects/Raspbian_LM75_temp_logger.html
This helps for comparing values
min=$(echo 12.45 10.35 | awk '{if ($1 < $2) print $1; else print $2}')
from here
http://unix.stackexchange.com/questions/24721/how-to-compare-to-floating-point-number-in-a-shell-script
Getting very close shell scripting a temperature alarm system now.
Hmm googling - been done:)
https://github.com/CapnBry/HeaterMeter/wiki/Alarm-Script-Recipes
Makes me wonder if I need decimal compares? +/- 1 degree should be ok/
-
Just realized this is RPi and I don't know if calc is included. Here are the contents of the script:
Yes it is included.
-
No bc but dc is in busybox, reverse Polish ???