Friday, 5 August 2016

How to add 2 numbers in shell script ?


Use $(expr ..) or $((..))

sum = $(expr "$num1" + "$num2")
echo $sum
OR

sum = $((num1 + num2)) 
echo $sum 

Following are incorrect commands :
echo $num1 + $num2;
echo `$num1` + `$num2`;

No comments:

Post a Comment

Note: only a member of this blog may post a comment.