syntax - How to do exponentiation in bash -


i try

echo 10**2  

it prints 10**2. how make work?

you can do:

let var=10**2   # sets var 100. 

or better , recommended way:

var=$((10**2))  # sets var 100. 

if want print expression result can do:

echo $((10**2)) # prints 100. 

for large numbers might want use exponentiation operator of bc as:

bash:$ echo 2^100 | bc 1267650600228229401496703205376 

if want store above result in variable can again use $(()) syntax as:

 var=$((echo 2^100 | bc))   

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -