Performing Floating Point Math with bc
The methods you’ve just seen for performing math operations from the shell all have two limitations. First, these methods can only work with integers. Secondly, when using these methods, you’re limited to just basic math. Fortunately, the bc
utility solves both of those problems. In fact, you’d need to be an expert mathematician to take full advantage of bc
's features. (I don’t fall into that category, but I can still show you the basics of using bc
.)
You should find that bc
is already installed on your Linux or Unix system, so you likely won’t have to mess around with installing it.
There are three ways to use bc
, which are:
- Interactive mode: You’ll just open
bc
, and enter math commands on its own command-line. - Program files: Create programs in the
bc
language, and usebc
to execute them. - Pipe math problems into bc: You can do this either from the shell command-line...