I try
echo 10**2
it prints 10**2
. How to make it work?
I try
echo 10**2
it prints 10**2
. How to make it work?
You can do:
let var=10**2 # sets var to 100.
or even better and recommended way:
var=$((10**2)) # sets var to 100.
If you just want to print the expression result you can do:
echo $((10**2)) # prints 100.
For large numbers you might want to use the exponentiation operator of bc
as:
bash:$ echo 2^100 | bc
1267650600228229401496703205376
If you want to store the above result in a variable you can again use the $(())
syntax as:
var=$((echo 2^100 | bc))
various ways
Bash
x=2
echo $((x**2))
Awk
awk 'BEGIN{print 2**2}'
bc
echo "2 ^ 2" |bc
dc
dc -e '2 2 ^ p'