- 论坛徽章:
- 95
|
原帖由 cyf2119128 于 2008-8-16 21:21 发表 ![]()
while (( 0<1 ))
do
tsecond=$(date +%S)
tt=$((tsecond%30))
问题就出在取模运算(%)这了,原因如下:
Numbers starting with leading 0 are Octal numbers (base 8) in many programming
languages including C, Perl and shell. Valid octal digits are
0,1,2,3,4,5,6,7 so it barfs if it sees an 8 or a 9. You probably want
to work in straight numbers and make a leading 0 in your output
format with a sprintf("%02d") kind of formatting thing.
Anything starting with 0x or 0X is a hex number.
So the error message means exactly as it says- it's an error from
the let function complaining about the value being too big for the base.
Have fun,
Stuart.
原贴地址:http://www.google.com/search?cli ... =UTF-8&oe=UTF-8
下面是解决办法:
You can explicitly state the base of a number using base#number
Code:
if [ $((10#$item)) -eq 0 ] ; then
That will have trouble if the number starts with a minus sign.
The '-' needs to be in front of the base like -10#009 for -9.
原贴地址:http://ubuntuforums.org/showthread.php?p=4206419
[ 本帖最后由 MMMIX 于 2008-8-16 23:21 编辑 ] |
|