bash脚本,非法数字:08 [英] Bash script, Illegal number: 08
问题描述
我运行在Ubuntu一个pretty简单的bash脚本,但已经提出了一个问题。
如果需要的话我会后整个脚本,但我已经缩小的问题。
基本上,我想运行一些$ C $每15秒C,所以我开始用这样的:
I'm running a pretty simple bash script in ubuntu but have come up with a problem. If needed I'll post the whole script, but I've narrowed down the problem. Basically, I want to run some code every 15 seconds, so I started with this:
time=`date +%S`
time2=$((time%15))
if [ $time2 -eq 0 ]
then
等等,等等,等等...
etc, etc, etc....
问题出现时,时间应该为:08秒。该脚本数目非法终止:08。
添加了这个,使用时:
The problem comes up when time is 08 seconds. The script terminates with Illegal number: 08. Adding to that, when using:
time2=$(($time%15))
而不是非法编号的错误,它会算术的前pression终止:期待EOF:08%15
instead of the illegal number error, it would terminate with Arithmetic expression: expecting EOF: "08%15"
我猜测08是不是PTED为数字间$ P $。还是有一些基本的问题,喜欢它认为它在八进制或东西。任何帮助吗?
I'm guessing 08 isn't interpreted as a number. Or there's some base issue, like it thinks it's in octal or something. Any help?
推荐答案
最短的解决方案:
time2=$(( ${time#0} % 15 ))
$ {VAR#水珠}
办法 $ VAR
与水珠
从一开始就删除,如果present。
${var#glob}
means "$var
with glob
removed from the beginning if present".
这篇关于bash脚本,非法数字:08的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!