WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Command line Calculator  (Read 3351 times)

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Command line Calculator
« 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?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: Command line Calculator
« Reply #1 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)'

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: Command line Calculator
« Reply #2 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 $* }"

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Command line Calculator
« Reply #3 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.

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Command line Calculator
« Reply #4 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/




Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Command line Calculator
« Reply #5 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.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Command line Calculator
« Reply #6 on: November 04, 2014, 08:32:13 PM »
No bc but dc is in busybox, reverse Polish ???