LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 652|回复: 2

有个问题很有意思!

[复制链接]
发表于 2006-9-25 13:44:19 | 显示全部楼层 |阅读模式
str="08";integer=$(($str+1));echo $integer
出现错误bash: 08: value too great for base (error token is "08")
感觉很奇怪,于是测试了一些其他的值
str="07"正确,06 05 04 03 02 01都正确
str="349938" 正确,开头不为0的数正确
str="016"错误输出15
str="017"错误输出16
str="0127"错误输出88
str="0128"bash: 08: value too great for base (error token is "0128")
发现任何出现8以及9的以0开头的数都出现此错误,恍然大悟,原来以0开头的数,bash会把其解释成8进制的数。
发表于 2006-9-25 14:07:22 | 显示全部楼层
Constants with a leading 0 are interpreted as octal numbers. A leading 0x or 0X denotes hexadecimal. Otherwise, numbers take the form [base#]n, where base is a decimal number between 2 and 36 representing the arithmetic base, and n is a number in that base. If base is omitted, then base 10 is used.


bash手册
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-25 14:14:16 | 显示全部楼层
thanks a lot这回终于彻底明白了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表