Search code examples
shellunixexponentiation

How can I evaluate simple math expressions in es?


For reference, I'm using this version of the shell.

I'm looking to evaluate a math expression containing exponents. How can I do so? expr isn't available in , and neither do the double parends work (as they do in other shells).

The expression I want to evaluate is 2^69 (2 to the 69th power). I've tried with both ** and ^ for exponentiation.

I'm looking for a solution that doesn't use an external calculator, hopefully pure code.


Solution

  • Most Unix shells delegate math to some other command. bc is probably available on your machine, since it's a POSIX utility. Invoke it from es like this:

    ; echo `{echo '2 ^ 69' | bc}
    590295810358705651712