Re: [opensuse] Command line calculator?





command line interface for dos or unix/linux???


from Larry


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

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



Relevant Pages

  • Re: [opensuse] Command line calculator?
    ... On Friday 29 June 2007 12:58, G T Smith wrote: ... calculator, and if so what it is called? ... echo $) ... (BASH has this, too, perhaps even better, being ...
    (SuSE)
  • Re: why wont my awk if/else work for both conditions?
    ... output1.txt; then echo y; else echo n; fi ... bash - but then stops. ... commands executed while in sh. ... but only when i type it directly into the prompt - not ...
    (comp.unix.shell)
  • Re: [opensuse] BASH - I give up : (
    ... Stuck on a stupid bash problem again. ... does not cause the creation of a sub-shell: the {curly brace}. ... commands in braces need to be terminated by a linefeed or a semicolon before the close brace. ... echo this ...
    (SuSE)
  • Re: floating-point arithmetics
    ... > simply would like to know what options or commands to use when I ... > For example how would I make the area calculator below work? ... > return $res ... echo "$res" ...
    (comp.unix.shell)
  • Re: nash initrd can be changed bash?
    ... some commands did not exist in the bash shell. ... The nash manpage explains the commands you are after - "man nash". ... > echo Mounted /proc filesystem ...
    (Fedora)