How can I print the sum of two numbers in shell script?

thanhthao

New member
How can I print the sum of two numbers in shell script?
Answer
Use the following syntax to calculate the sum of two integers in a shell script:
  1. Using expr command with quotes sum=`expr $num1 + $num2`
  2. Use expr command inclosed with brackets and start with dollar symbol. sum=$(expr $num1 + $num2)
  3. This is my preferred way to directly with the shell. sum=$(($num1 + $num2))
 

Tìm kiếm

Back
Top