bc

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

bc is an arbitrary-precision fixed-point mathematical scripting language with a C-like syntax. In modern usage, bc is typically used to overcome the limitations of shell scripting languages which are often restricted to integer arithmetic. In this capacity it is usually embedded into an existing shell script with either a pipe or a HERE-DOCUMENT statement. Use cases requiring floating-point calculations embedded into shell scripts typically call for Perl, Ruby, or Raku in place of bc as all three are one-liner friendly languages.

Installation

USE flags

USE flags for sys-devel/bc Handy console-based calculator utility

libedit Use the libedit library (replacement for readline)
readline Enable support for libreadline, a GNU line-editing library that almost everyone wants
static !!do not set this during bootstrap!! Causes binaries to be statically linked instead of dynamically

Emerge

Emerge sys-devel/bc:

root #emerge --ask sys-devel/bc

Environment variables

  • POSIXLY_CORRECT follow the POSIX standard to the letter. The -s switch has the same effect.
  • BC_ENV_ARGS arguments to be passed into bc by default.
  • BC_LINE_LENGTH An integer specifying the number of characters per line of output.

Usage

user $bc --help
usage: bc [options] [file ...]
  -h  --help         print this usage and exit
  -i  --interactive  force interactive mode
  -l  --mathlib      use the predefined math routines
  -q  --quiet        don't print initial banner
  -s  --standard     non-standard bc constructs are errors
  -w  --warn         warn about non-standard bc constructs
  -v  --version      print version information and exit

Removal

Unmerge

Uninstall sys-devel/bc:

root #emerge --ask --depclean --verbose sys-devel/bc

See also

  • sc — a terminal-based spreadsheet and calculator with vim-like key bindings
  • ledger — a scriptable double-entry accounting system for the command-line