Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从当天(24Feb13 day#55)中减去上课的第一天(17Feb13 day#47)该命令date +%j产生 055,而不是 55,所以数学错误......
date +%j
todayIn=$(date +%j)......= 055
todayIn=$(date +%j)
firstDay=(47).....................= 47
firstDay=(47)
myVal=$(todayIn-firstDay)....= 错误(预期为 8)
myVal=$(todayIn-firstDay)
似乎只需用以下内容去除前导零就足够了:
todayIn=$(date '+%j' | sed -e 's/^0*//')
或使用expr:
expr
$ a=$(expr 055 - 5) $ echo $a $ 50