Bash - variable exponents when raising power
<p>This works</p>

<pre><code>answer=$(echo "2^3" | bc)
$ 8
</code></pre>

<p>However, this does not.  Here is the full script:</p>

<pre><code>#!/bin/bash
myvar=$(echo "4-1" | bc)    
answer=$(echo "2^$myvar" | bc)
echo $answer
</code></pre>

<p>When I run this with 'set -x', this is the output</p>

<pre><code>./test.sh: line 3: syntax error near unexpected token '|'
./test.sh: line 3: 'myvar=(echo "4-1" | bc)
++ echo '2^'
++ bc
(standard_in) 2: syntax error
+ answer=
+ echo
</code></pre>

<p>I want to stick with bc, but can't figure out how to pass a var as an exponent.</p>