且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在UNIX中将字符串转换为整数

更新时间:2023-02-03 08:59:45

标准解决方案:

 expr $d1 - $d2

您也可以这样做:

echo $(( d1 - d2 ))

,但是请注意,这会将07视为八进制数字! (因此077相同,但01010不同).

but beware that this will treat 07 as an octal number! (so 07 is the same as 7, but 010 is different than 10).