gcalccmd
Evaluate mathematical expressions from the command line
SYNOPSIS
gcalccmd [options] expression
PARAMETERS
-l
Load the bc math library.
--scale=number
Set the bc scale variable to the specified number of decimal places. This determines the precision of the calculations.
expression
The arithmetic expression to be evaluated by bc. Enclose expressions containing spaces or special characters in quotes.
DESCRIPTION
gcalccmd is a command-line utility that provides a simple interface to perform calculations using the GNU bc (arbitrary precision calculator) program. It reads expressions from the command line, evaluates them using bc, and prints the results to standard output. This allows for quick and easy calculations without the need to start an interactive bc session.
It is particularly useful in scripts or for performing calculations directly in the terminal. gcalccmd handles basic arithmetic, functions (like sine, cosine, tangent, logarithm, exponential), and variable assignments supported by bc. It passes the arguments given to it to bc and prints the result on standard output. If there are errors, it prints the errors on standard error.
It supports expressions involving integers, floating-point numbers and math functions from the bc's math library, which can be accessed using `-l` option. You can assign the bc’s `scale` variable, to control the decimal places, using `--scale`.
CAVEATS
gcalccmd relies on the presence of GNU bc on the system. Without bc, it will not function. The expression passed to gcalccmd must be a valid bc expression. gcalccmd doesn’t do any parsing or error checking itself.
EXAMPLES
gcalccmd '2 + 2'
This will print `4`.
gcalccmd -l 's(1)'
This will print `0.84147098480789650622` (sine of 1 radian using the math library).
gcalccmd --scale=5 '10 / 3'
This will print `3.33333`.
HISTORY
gcalccmd is typically a small utility created to simplify using `bc` in shell scripts and command-line environments. The development is focused on creating a direct and user-friendly approach to evaluate expressions with bc. Usage grows in environments needing arithmetic computations inline without direct interaction to a calculator.
SEE ALSO
bc(1)