in general i will use expr inside shell scripts for doing arithmetic operations.
is there a way where we can come up with arithmetic operation in a shell script without using expr?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Did you tried to read “man ksh” if you’re using ksh?
“man bash”, for example, has enough information on doing arithmetics with bash.
the command typeset -i can be used to specify that a variable must be treated as an integer, for example typeset -i MYVAR specifies that the variable MYVAR is an integer rather than a string. Following the typeset command, attempts to assign a non integer value to the variable will fail:
To carry out arithmetic operations on variables or within a shell script, use the let command. let evaluates its arguments as simple arithmetic expressions. For example:
The expression above could also be written as follows:
Anything enclosed within $(( and )) is interpreted by the Korn shell as being an arithmetic expression