Hi,
How can i do the mathematical calculations in bash shell?
Are the mathematical functions available in bash shell?
Ex:
pow
ceil
floor
sqrt
Hi,
How can i do the mathematical calculations in bash shell?
Are the mathematical functions available in bash shell?
Ex:
pow
ceil
floor
sqrt
the bc command support pow and sqrt function. floor and ceil, i'm not sure if any command supports. You can write a function for your own require.
Regards.
Can you post the example code for pow function?
Hello!
Your question(s) could easily be answered by searching the Internet with Google. Google is your friend
Per forum rules, and the benefit of all users, please search the network and the forums before posting a question.
You can easily search the forums using our internal Google search engine or our advanced internal search engine. You can also search our huge UNIX and Linux database by user generated tags or search the database for unanswered questions and provide an answer.
Thank you.
---------------------------------------------------------------------
Check this link found with Google:
bc programming language - Wikipedia, the free encyclopedia
The UNIX and Linux Forums
To answer your question
Unfortunately no. Bash only supports integer arithmetic and does not have support for libm functions.
The only commonly used shells that support floating point are zsh and ksh93.
This is a shell function:
pow() #@ USAGE: pow base exponent
{
echo $(( ${1:?} ** ${2:?} ))
}