• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

bc: command not found

by admin

bc is a calculator scripting language. Scripts in bc can be executed with the bc command. Imagine a test.bc file contains the following code:

scale = 2;
(10.0*2+2)/7;

That means you can run bc like this:

$ cat test.bc | bc
3.14

bc can do far more than just divide two numbers. It’s a fully-fledged scripting language on its own and you can do arbitrarily complex things with a bc script. A bc script might be the ending point of a pipeline of data, where the data files are initially massaged into a stream of data rows, and then a bc script is used to compute the values we’re looking for.

You can omit the copyright messages displayed while running bc using the “-q” option with it.

$ bc –q
2 + 2
4
quit

The ability to take standard input means we can use documents, strings, and pipes to pass scripts. This is a here string example:

$ bc <<< "2+2"
4

If you get an error as shown below while executing the bc command:

bc: command not found

you may try installing the bc package as shown below as per your choice of distribution.

Distribution Command
OS X brew install bc
Debian apt-get install bc
Ubuntu apt-get install bc
Alpine apk add bc
Arch Linux pacman -S bc
Kali Linux apt-get install bc
CentOS yum install bc
Fedora dnf install bc
Raspbian apt-get install bc

The bash calculator recognizes these:

  • Numbers (both integer and floating point)
  • Variables (both simple variables and arrays)
  • Comments (lines starting with a pound sign or the C language /* */ pair)
  • Expressions
  • Programming statements (such as if-then statements)
  • Functions

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to monitor your CPU on debian or ubuntu systems
  2. How to Increase KVM Guest vCPU Resources
  3. Linux OS service ‘portmap’
  4. CentOS / RHEL 4 : How to configure interface bonding (NIC teaming)
  5. setsebool: command not found
  6. mumble Command Examples in Linux
  7. lvdisplay: command not found
  8. How to Start, Stop and Restart Zimbra Service
  9. mpstat Command Examples in Linux
  10. Linux OS Service ‘squid’

You May Also Like

Primary Sidebar

Recent Posts

  • ncat Command Examples in Linux
  • ncat: command not found
  • nautilus Command Examples in Linux
  • namei: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright