Raise to the power in shell

Linas picture Linas · Oct 28, 2012 · Viewed 56.3k times · Source

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.

Answer

Brian Agnew picture Brian Agnew · Oct 28, 2012

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.