Shell脚本中有关数据进制的问题(value too great for base (error token is "08"))
Posted javartisan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shell脚本中有关数据进制的问题(value too great for base (error token is "08"))相关的知识,希望对你有一定的参考价值。
脚本内容:
#!/usr/bin/env bash
endWeek=`date +%V`
echo $endWeek
startWeek=$[`date +%V`-1]
year=`date +%Y`
if [[ $# -eq 2 ]]
then
echo "please input startWeek and endWeek (week >=startWeek and week < endWeek) !"
startWeek=$1
endWeek=$2
else
echo "because of you don't input start and end date, use lastWeek and curWeek!"
fi
basePath=$(cd `dirname $0`;pwd)
pid=0
while [[ $startWeek -lt $endWeek ]]
do
echo $year
echo $startWeek
#do something 忽略
startWeek=$[$startWeek+1]
done
exit $pid
当前日期:2020-02-19
运行报错:
week_report_generator_with_bug.sh: line 7: 08: value too great for base (error token is "08")
出错的原因:Shell脚本中0开头的数字表示8进制,因此08则超出了8进制的范围。
知识点:Shell数据进制
Shell文档:https://bash.cyberciti.biz/shell/shell-math/
以上是关于Shell脚本中有关数据进制的问题(value too great for base (error token is "08"))的主要内容,如果未能解决你的问题,请参考以下文章