I have d1="11" and d2="07". I want to convert d1 and d2 to integers and perform d1-d2. How do I do this in UNIX?
d1="11"
d2="07"
d1
d2
d1-d2
d1 - d2 currently returns "11-07" as result for me.
d1 - d2
"11-07"
The standard solution:
expr $d1 - $d2
You can also do:
echo $(( d1 - d2 ))
but beware that this will treat 07 as an octal number! (so 07 is the same as 7, but 010 is different than 10).
07
7
010
10
2.1m questions
2.1m answers
60 comments
56.8k users