Script to raise a integer by a exponent (while loop)

I am trying to write a script that raises a integer (m) by a exponent (n) using a while loop

ex. 5 raised to the power of 2 ..

I am a beginner and i dont know what is the opperand or command i have to use to make this happen..this is what i have so far...

echo "Enter a integer for the base"
read m
echo "Enter a positve integer for the power"
read n
while [ $m -gt 0 ]
do
  exp=$(( m ^ n ))
echo $exp
done

This just gives a infinite loop of the sum...can someone please help?

---------- Post updated 10-19-10 at 01:52 AM ---------- Previous update was 10-18-10 at 09:32 PM ----------

Ok .. i got this far but i cant make it display the output without it going to an infinite loop:(! Please help! :confused:

c=0
i=1
echo "Enter an integer for the base"
read m
echo "Enter Enter a positive integer for the power"
read n
while (( i > 0 ))
do
  c=$(($m**$n))
done
echo "The product of the numbers is: $c"

if i insert

echo "echo "The product of the numbers is: $c"

it goes into an infinite loop giving me the answer...if i don't...it just keeps asking me for the second integer!

The problem is with var i whose value is 1 which is always greater than Zero according to your while condition.. Hence you get a infinite loop.

while (( i > 0 ))

:slight_smile: you're not doing anything that requires a loop! Remove the while loop and your problems are solved!

@ umer -- salam .. you are absolutely right! i was just about to reply that....i was trying different things then i realized...i dont even need a loop:eek: lol ... so this is what i got and it works!

echo "Enter an integer for the base"
read m
echo "Enter Enter a positive integer for the power"
read n
c=$(($m**$n))
echo " "
echo "$m raised to the power of $n is: $c"

thanks for the replies :slight_smile: