1

I have a problem with numbers 08 and 09. When I get the number of the day of the month (01..04...09...), and I use it inside an if, I receive an error with numbers 08 and 09. How can I solve this error?

The error is [[: 09: value too great for base (error token is "09") I don't get any error with the other numbers.

datelaptop=`date +"%d"`
echo $datelaptop
if [[ $datagfs -eq $datelaptop ]] ; then
#if [[ 09 -eq 09 ]] ; then

Thank you for your help

Enric Agud Pique
  • 1,087
  • 7
  • 13
  • 30

1 Answers1

2

That is because 08 and 09 have a leading zero and are being interpreted as octal numbers. 08 and 09 are invalid octal numbers hence this error.

You can use base 10 arithmetic in ((...)) to compare 2 values:

if (( 10#$datagfs == 10#$datelaptop )); then
...
fi

10#$datagfs will interpret 08 to 8

anubhava
  • 761,203
  • 64
  • 569
  • 643