08 value too great for base error token is 08

So, I'm trying to calculate 12-08 (not 12-8) and get the following error: let: 08: value too great for base (error token is "08") Here's the sample code: first=12 second=08 if [[ ($first > $s...

So, I’m trying to calculate 12-08 (not 12-8) and get the following error:

let: 08: value too great for base (error token is "08")

Here’s the sample code:

first=12
second=08
if [[ ($first > $second) ]]; then
    let fin=first-second
else
    let fin=second-first
fi

P.S Sorry about the spacings

terdon's user avatar

terdon

96.2k15 gold badges192 silver badges289 bronze badges

asked May 9, 2016 at 11:03

EmberSpirit's user avatar

1

If you precede a number by 0, bash treats the number as octal. As octal is base 8 with digits ranging from 0 to 7, 08 is out of range for octal.

Now you have two options to do decimal calculation:

  • Omit preceding 0:

    $ echo $(( 12 - 8 )) 
    4
    
  • Explicitly mention base as decimal by 10#:

    $ echo $(( 12 - 10#08 )) 
    4
    

Community's user avatar

answered May 9, 2016 at 11:11

heemayl's user avatar

heemaylheemayl

88.8k19 gold badges195 silver badges262 bronze badges

3

Trying to do quiz ‘max sum of 2 from grid’

Can’t figure out how to get around the error below.

Feels like I’m missing something. Once I find out what I can update the question to be more general and applicable to others perhaps.

Line 32: value too great for base (error token is "08")

#!/bin/bash
setup () {
  grid=(01 02 03 04 05 06 07 08 07 06 05
        12 13 14 15 16 15 14 13 12 11 11
        05 06 06 07 07 07 06 06 05 05 04)
  n=${#grid[@]}
  number_of_lines=$((n / 11))
  length_of_line=$1
  largest_sum=0
  largest_pos=0
}
largest_2 () {
  for ((row=0; row < number_of_lines; row++)) {
    for ((column=0; column<length_of_line-1; column++)) {
      larger_horizontal
      if [[ $row -lt $number_of_lines-1 ]]; then
        larger_vertical
      fi
    }
  }
}
larger_vertical () {
  sum=$((grid[column+row*11]*grid[column+(row+1*11)]))
  if [[ $sum -gt $largest_sum ]]; then
    largest_sum=$sum
    largest_pos=$((column+row*11))
    direction=vertical
    result=$largest_pos
  fi
}
larger_horizontal () {
  sum=$((grid[column+(row*11)]*grid[column+1+(row*11)])) # <-- Line 32
  if [[ $sum -gt $largest_sum ]]; then
    largest_sum=$sum
    largest_pos=$((column+(row*11)))
    direction=horizontal
    result=$largest_pos
  fi
}

setup 11
largest_2
printf "n1. Max: row=$((result / 11 +1)) column= $((result % 11 +1)) direction=$directionn"

asked Feb 16, 2015 at 0:59

Michael Durrant's user avatar

Michael DurrantMichael Durrant

40.1k69 gold badges159 silver badges230 bronze badges

2

08 starts with a 0 thus is regarded as octal in some contexts (with digits between 0 and 7, hence the error beginning at 08). The solution: filter out the 0; if you need to output a leading 0, there’s printf %02d.

answered Feb 16, 2015 at 1:01

vinc17's user avatar

vinc17vinc17

11.6k36 silver badges44 bronze badges

3


0

0

Есть скрипт (Хитрый велоси^таймер) в котором есть строки

 MINUTESYS1=`date +%M`
        if [ $VAR1 -eq $MINUTESYS1 ] ; then # строка 300
            VAR1=`echo $(($MINUTESYS1 + $WAIT))` # строка 301 соответственно
            CallRunProg
        else
            blablabal

WAIT=[0-60] время в минутах через которое надо запускать функцию CallRunProg

Временами вылетает такая вот ошибка.

Tue, 31 Aug 2010 22:07:09 +0700 Runtimer.bsh[26323]:(root) RUN (run-parts /etc/runtimer/workfolder ) successfully!
./Runtimer.bsh: line 301: 08: value too great for base (error token is "08")
Tue, 31 Aug 2010 22:08:09 +0700 Runtimer.bsh[26323]:(root) RUN (run-parts /etc/runtimer/workfolder ) successfully!
./Runtimer.bsh: line 300: [: -eq: ожидается использование унарного оператора
./Runtimer.bsh: line 300: [: -eq: ожидается использование унарного оператора

Понятно что переменная VAR1 почему то не присвоилась в один прекрасный момент.
И в основной это случается когда значение переменной MINUTESYS1 равно 08.
Кто нибудь знает как это можно поправить?

This is part of the
Semicolon&Sons Code Diary
— consisting of lessons learned on the job. You’re in the
bash category.

Last Updated: 2023-02-08

I got sporadic errors with this script:

#!/usr/bin/env bash

minutes=$(date +%M)

if [[ $((minutes % 10)) -eq $starting_minute ]]; then
   my_cmd
fi

The errors said:

08: value too great for base (error token is "08")

This happened when I ran the script at 19.08, causing $minutes to be «08». The
issue here is that bash tries to interpret 08 as an octal number, since it
starts with a zero. However, only the digits 0-7 are allowed in octal — decimal
8 is octal 010. Hence 08 is not a valid number, and that’s the reason for the
error.

The workarond for this, given that the date command returns minutes with a
leading 0, is to explictly give the base with 10#$var

if [[ $(( 10#$minutes % 10)) -eq $starting_minute ]]; then
   my_cmd
fi

Lessons

  • watch out for octal numbers when anything starts with 0 e.g. 08 vs 8

Resources

  • https://stackoverflow.com/questions/24777597/value-too-great-for-base-error-token-is-08

Получается, конечно, громоздко…. но пока только так. И то не работает(

for year in {1981..1981} ; do

for month in {1..12} ; do

for stday in 01 06 11 16 21 26
do

if [[ $month =~ ^[1-9]$ ]] ; then
#month=${month/#/0}
month=$(( 10#${month/#/0} ))
fi

if [[ $stday -eq 01 ]] ; then
enday=05
fname1=’flxl01.gdas.’$year»$month»$stday’-‘$year»$month»$enday’.grb2.nc’
echo $fname1

elif [[ $stday -eq 06 ]] ; then
enday=10
fname1=’flxl01.gdas.’$year»$month»$stday’-‘$year»$month»$enday’.grb2.nc’
echo $fname1

elif [[ $stday -eq 11 ]] ; then
enday=15
fname1=’flxl01.gdas.’$year»$month»$stday’-‘$year»$month»$enday’.grb2.nc’
echo $fname1

elif [[ $stday -eq 16 ]] ; then
enday=20
fname1=’flxl01.gdas.’$year»$month»$stday’-‘$year»$month»$enday’.grb2.nc’
echo $fname1

elif [[ $stday -eq 21 ]] ; then
enday=25
fname1=’flxl01.gdas.’$year»$month»$stday’-‘$year»$month»$enday’.grb2.nc’
echo $fname1

else
if [[ $month -eq 01 || $month -eq 03 || $month -eq 05 || $month -eq 07 || $month -eq 08 || $month -eq 10 || $month -eq 12 ]] ; then
enday=31
fi
if [[ $month -eq 04 || $month -eq 06 || $month -eq 10#09 || $month -eq 11 ]] ; then
enday=30
fi
if [[ $month -eq 02 ]] ; then
if [ $[$year % 4] -ne «0» ]; then
enday=28
else
enday=29
fi
fi
fname1=’flxl01.gdas.’$year»$month»$stday’-‘$year»$month»$enday’.grb2.nc’
echo $fname1

fi
done
done
done

Понравилась статья? Поделить с друзьями:

Читайте также:

  • 0771 код ошибки
  • 077 901 ошибка xerox
  • 077 900 ошибка xerox
  • 0769 ошибка тигуан
  • 0768 ошибка фольксваген

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии