Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: gavinmc42 on October 29, 2014, 11:17:03 PM

Title: Command line Calculator
Post 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?
Title: Re: Command line Calculator
Post by: Rich on October 29, 2014, 11:35:55 PM
Hi gavinmc42
There is a  calc  script in  /usr/bin/  that utilizes awk. Try entering this at the command line:
Code: [Select]
calc 'sqrt(2)'
Title: Re: Command line Calculator
Post by: Rich on October 29, 2014, 11:48:12 PM
Hi gavinmc42
Just realized this is RPi and I don't know if calc is included. Here are the contents of the script:
Code: [Select]
#!/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 $* }"
Title: Re: Command line Calculator
Post by: gavinmc42 on October 30, 2014, 12:23:03 AM
Thanks,

Typed calc into terminal and something came up, so it's there
Yep does floating point, yippee.
Title: Re: Command line Calculator
Post by: gavinmc42 on October 30, 2014, 01:36:16 AM
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/



Title: Re: Command line Calculator
Post by: bmarkus on October 30, 2014, 01:44:12 AM

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.
Title: Re: Command line Calculator
Post by: gavinmc42 on November 04, 2014, 08:32:13 PM
No bc but dc is in busybox, reverse Polish ???