Calculator on the go

echo 2+3 |bc
Handy use of bc in the command line. No need to get 'into' the bc to perform calculations
Sample Output
# echo 2+3 |bc

By: Kaio
2009-07-04 22:03:41

These Might Interest You

  • A bitcoin "brainwallet" is a secret passphrase you carry in the "wallet" of your brain. The Bitcoin Brainwallet Private Key Calculator calculates the standard base58 encoded bitcoin private key from your "brainwallet" passphrase. The private key is the most important bitcoin number. All other numbers can be derived from it. This command uses 3 other functions - all 3 are defined on my user page: 1) brainwallet_exponent() - search for Bitcoin Brainwallet Exponent Calculator 2) brainwallet_checksum() - search for Bitcoin Brainwallet Exponent Calculator 3) b58encode() - search for Bitcoin Brainwallet Base58 Encoder Do make sure you use really strong, unpredictable passphrases (30+ characters)! can be used to check the accuracy of this calculator. Show Sample Output

    (read -r passphrase; b58encode 80$( brainwallet_exponent "$passphrase" )$( brainwallet_checksum "$passphrase" ))
    nixnax · 2014-02-18 02:50:09 0
  • This is an "argument calculator" funktion. The precision is set to 4 and you can use dot (.) or comma (,) as decimal mark (which is great for german users with a comma on the numpad).

    calc() { echo "scale=4; ${*//,/.}" | bc -l; }
    fpunktk · 2011-10-24 19:58:20 0
  • use python as calculator, press ctrl+d to exit reminder: when doing factions add atleast one decimal number like so 22.0/7 or 22/7.0 Show Sample Output

    alias calc='python -ic "from math import *; from random import *"'
    Bonster · 2011-10-24 08:15:41 0
  • bc is a wonderful calculator. Just type bc at the command line and have at it. Ctrl+D (or type quit) will get you out. This usage is just scratching the surface: bc can handle a mini scripting language, complete with variable, statements, loop, conditional statements and more. Do a man page on it to find out. Show Sample Output

    haivu · 2009-03-24 16:19:12 3

What Others Think

penpen · 467 weeks and 4 days ago
hmm, it seems as if that triple less ran into trouble. Let's see if this works: bc <<< 2+3
penpen · 467 weeks and 4 days ago
I use calc() { echo $@ | bc -ql; }
bandie91 · 467 weeks and 4 days ago
bash is already the calculation echo $((2+3)) 5
Playload · 467 weeks and 3 days ago
nice, but bash already has built-in math, also via `expr` and `let` still up-voting because bc is the bomb-diggity
linuxrawkstar · 467 weeks and 3 days ago
<<< 2+3 bc
mpb · 467 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: