Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at the bc command – it’s a command line calculator. To start bc, you just type “bc”.
After a brief heading, bc waits for your input. You can exit by typing “quit” or start handing bc calculations that you want it to perform for you. Here’s an easy subtraction:
Now, let’s get a little more complicated:
The parenthesized part in that example ensures that the subtraction is done before the multiplication. In this next example, we calculate both the square and the cube of 11.
You can also assign values to variables – helpful if you want to reuse a value without having to reenter it.
You can even decide how many decimal places you want to see in your results.
That’s your Linux tip for the bc command.
If you have questions or would like to suggest a topic, please add a comment below.
And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.