shellexponential

Raise to the power in shell


How do you raise m to the power of n? I've searched for this everywhere. What I found was that writing m**n should work, but it doesn't. I'm using #!/bin/sh.


Solution

  • I would try the calculator bc. See http://www.basicallytech.com/blog/index.php?/archives/23-command-line-calculations-using-bc.html for more details and examples.

    eg.

    $ echo '6^6' | bc
    

    Gives 6 to the power 6.