Value too great for base (error token is “09”)

后端 未结 6 1548
我寻月下人不归
我寻月下人不归 2020-11-27 06:31

When running this part of my bash script am getting an error

Script

value=0
for (( t=0; t <= 4; t++ ))
do
d1=${filedates[$t]}
d2=${filedates[$t+1]         


        
相关标签:
6条回答
  • 2020-11-27 07:19

    For 'mm' and 'dd' values in dates, I use this trick:

    mm="1${date:5,2}"  # where 5 is the offset to mm in the date
    let mm=$mm-100     # turn 108 into 8, and 109 into 9
    
    0 讨论(0)
  • 2020-11-27 07:21

    Prepend the string "10#" to the front of your variables. That forces bash to treat them as decimal, even though the leading zero would normally make them octal.

    0 讨论(0)
  • 2020-11-27 07:27

    d1 and d2 are dates in that form 2014-01-09 and 2014-01-10

    and then

    ((diff_sec=d2-d1))
    

    What do you expect to get? ((diffsec=2014-01-09-2014-01-10)) ??

    You need to convert the dates to seconds first:

    d1=$( date -d "${filedates[$t]}" +%s )
    d2=$( date -d "${filedates[$t+1]}" +%s )
    (( compare = (d2 - d1) / (60*60*24) ))
    (( value += compare ))
    
    0 讨论(0)
  • 2020-11-27 07:32

    What are d1 and d2? Are they dates or seconds?

    Generally, this error occurs if you are trying to do arithmetic with numbers containing a zero-prefix e.g. 09.

    Example:

    $ echo $((09+1))
    -bash: 09: value too great for base (error token is "09")
    

    In order to perform arithmetic with 0-prefixed numbers you need to tell bash to use base-10 by specifying 10#:

    $ echo $((10#09+1))
    10
    
    0 讨论(0)
  • 2020-11-27 07:32

    The fowllowing code occur the same error , I don't know why, but already solved it:

    24    echo $currentVersion
    25    if [[ $currentVersion -eq "" ]];then
    26       echo "$projectName=$version">>$modulepath
    27    else
    28       sed  -i "s/^$projectName=$currentVersion/$projectName=$version/g"  $modulepath
    29    fi
    

    ERROR INFO:

    b26044fb99c28613de9903db3a50cbb11f0de9c7 1e5d11c9923045cc43f5fdde07f186b6dd5ca1b4
    /data/ext/tbds_ci_build/tbds_build_common.sh: line 25: [[: b26044fb99c28613de9903db3a50cbb11f0de9c7
    1e5d11c9923045cc43f5fdde07f186b6dd5ca1b4: value too great for base (error token is "1e5d11c9923045cc43f5fdde07f186b6dd5ca1b4")
    sed: -e expression #1, char 63: unterminated `s' command
    

    Fix:

    Make $currentVersion do not contain 2 values like "a b", just 1 value "a" .
    
    0 讨论(0)
  • 2020-11-27 07:35

    You don't need the $ and the {} in an arithmetic expansion expression. It should look like this:

    compare=$((SEC/(60*60*24)))
    
    0 讨论(0)
提交回复
热议问题