Name

bc

Synopsis

    bc [options] [files]

Interactively perform arbitrary-precision arithmetic or convert numbers from one base to another. Input can be taken from files or read from the standard input. To exit, type quit or EOF.

bc is a language (and compiler) whose syntax resembles that of C, but with unlimited-precision arithmetic. bc consists of identifiers, keywords, and symbols. Examples are given at the end. GNU/Linux and Mac OS X both use GNU bc.

URL: http://www.gnu.org/software/bc/.

Common Option

-l, --mathlib

Make functions from the math library available. This is the only option required by POSIX.

Solaris Options

-c

Do not invoke dc; compile only. (On Solaris, and on most commercial Unix systems, bc is a preprocessor for dc, so bc normally invokes dc.)

GNU bc Options

-h, --help

Print help message and exit.

-i, --interactive

Interactive mode.

-q, --quiet

Do not display welcome message.

-s, --standard

Ignore all extensions, and process exactly as in POSIX.

-v, --version

Print version number.

-w, --warn

When extensions to POSIX bc are used, print a warning.

Examples

Note in these examples that when you type some quantity (a number or expression), it is evaluated and printed, but assignment statements produce no display:

    $ bc              
                     Stat the program
                     ibase = 8         
                     Octal input
                     20                
                     Evaluate this octal number
    16                Terminal displays decimal value
                     obase = 2         
                     Display output in base 2 instead of base 10
                     20                
                     Octal input
    10000             Terminal now displays binary value
                     ibase = A         
                     Restore base 10 input
                     scale = 3         
                     Truncate results to three ...

Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.