Search code examples
bashshellunixshbc

How to calculate the log of a number using bc?


I want to calculate the log (base 10) of a number. How can I do this using bc?


Solution

  • Invoke bc with the -l option (to enable the math library) like so:

    $ echo 'l(100)/l(10)' | bc -l
    2.00000000000000000000
    

    Use the l function which is the natural log. Take the natural log of the number you are interested in then divide it by the natural log of 10.