Re: [opensuse] Command line calculator?



On Friday 29 June 2007 12:58, G T Smith wrote:
Adam Jimerson wrote:
Does anyone know if there is a program for a command line
calculator, and if so what it is called?

bash :-)

try

echo $((5+2))
echo $((7*6))

Or, try these:

% echo $(( 5.5 + 2.2 ))
bash: 5.5 + 2.2: syntax error in expression (error token is ".5 + 2.2 ")

% echo $(( 010 * 020 ))
128

% echo $(( 080 + 020 ))
bash: 080: value too great for base (error token is "080")

% echo $(( 0xa * 0xa ))
100


at CLI

of course if you want trig and logs you need do a little work...


It only does integers and has an inflexible way of treating numeric
radixes (e.g., leading zero forces octal), as shown above.

Dc (RPN) or bc (infix) are the way to go for non-trivial scripted
calculation. They do floating point, arbitrary precision and have
formatted printing. (BASH has this, too, perhaps even better, being
modelled after the C library printf() function.)


Randall Schulz
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx



Relevant Pages

  • Re: [opensuse] Command line calculator?
    ... line calculator, and if so what it is called? ... echo $) ... (BASH has this, ... For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx ...
    (SuSE)
  • Re: PATH variable
    ... Floyd L. Davidson wrote: ... >>which should result in echo $PATH ... configuration files before bash invokes /etc/profile ... > come to a single line in a single file that in fact does modify ...
    (comp.os.linux.misc)
  • Re: Bash script - telnet
    ... > I need a telnet script in bash. ... (echo user your_username ... Notice that "echo" preceeds the commands to the remote server. ...
    (comp.unix.questions)
  • Re: Probably very stupid script/bash question
    ... both solutions work perfectly under bash. ... echo "Data received = $E Bytes" ... If the first line has white space, then as many variables as there are "fields" in the line will contain values. ... you must have one or more white spaces between the two 'less than' symbols and NO space between the 'less than' and the 'left parenthesis'. ...
    (Debian-User)
  • Re: Error returns not =?utf-8?q?handled=09correctly=09by=09sysfs=2Ec=3Asubsys=5Fattr=5Fstore?=()
    ... Used /bin/echo instead of the built-in echo command. ... Zsh and Bash both fail. ... AMD running Debian lenny with i686 kernel -- fails. ...
    (Linux-Kernel)