when someone abandons you,it is him that gets loss because he lost someone who truly loves him but you just lost one who doesn’t love you.
1 | seed=$((${RANDOM}${RANDOM} % 99999 +1)) |
本来是想用系统变量拼凑出一个随机数的,但是没想到居然在多次使用过程中跑出一个错误 07881: value too great for base (error token is "07881")
虽然问题本身比较少,但是好在不难找到问题缘由,因为 07881 这个字符串是 0 开头,所以 shell 在计算数字的时候把它看作八进制数字处理了,所以八进制数字中出现 8 自然是不被允许的
再准确一点,从 man bash 中的 ARITHMETIC EVALUATION 可以找到对应的描述:
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 64 representing the arithmetic base, and n is a number in that base. If base# is omitted, then base 10 is used. The digits greater than 9 are represented by the lowercase letters, the uppercase letters, @, and _, in that order. If base is less than or equal to 36, lowercase and uppercase letters may be used interchangeably to represent numbers between 10 and 35.
从这段描述中也不难找到解决方法:
1 | seed=$((10#${RANDOM}${RANDOM} % 99999 +1)) # 只需要在数字字符串之前加上 10#,就能避免被认错进制的问题了 |
be slow to promise and quick to perform.