LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2013, 04:32 PM   #1
cli
Member
 
Registered: Apr 2013
Distribution: RedHat, Cent, Ubuntu
Posts: 80

Rep: Reputation: Disabled
bash error as [[: 08: value too great for base (error token is "08")


Hi All,
I am testing conditions with below script and wanted to run the commands on all of the day but only execpt the date of month 1st and except the day of sunday.
Code:
$ cat test1
#!/bin/bash
Today_Date=$(date '+%d')
Today_Week=$(date '+%w')
if  [[ $Today_Date -ne 1 || $Today_Week -gt 0 ]]; then
echo "Today is neither month 1st, nor sunday."
fi
changed date using mmddhhmmyyyy(month,date,hour,minutes,year)
Code:
sudo date 060100002013
$ date
Sat Jun  1 00:03:22 IST 2013
$ bash test 
Today is neither month 1st, nor sunday.
Why?
Then I changed to Sunday date.
Code:
sudo date 060900002013
$ date
Sun Jun  9 00:00:06 IST 2013
$ bash test
Today is neither month 1st, nor sunday.
Why? Sometimes I'll get the below error also
Code:
[[: 08: value too great for base (error token is "08")
So please help me to run this script all of the day except month 1st and Sunday.

Thanks in adavance for your kind help.

Last edited by cli; 06-07-2013 at 04:59 PM.
 
Old 06-07-2013, 05:02 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,117

Rep: Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339
The leading zero makes "08" look like an octal number with an invalid digit. Either tell the date command to pad with spaces rather than zero ("date +%e" or "date +%_d"), or else explicitly identify the base when you use the value:
Code:
if  [[ 10#$Today_Date -ne 1 || $Today_Week -gt 0 ]]; then
 
2 members found this post helpful.
Old 06-07-2013, 05:15 PM   #3
cli
Member
 
Registered: Apr 2013
Distribution: RedHat, Cent, Ubuntu
Posts: 80

Original Poster
Rep: Reputation: Disabled
Thanks for the reply rknichols,
But still both methods are not working for me.
Code:
$ date
Sun Jun  9 00:09:48 IST 2013

$ cat test1
#!/bin/bash
Today_Date=$(date '+%e')
Today_Week=$(date '+%w')
if [[ $Today_Date -ne 1 || $Today_Week -gt 0 ]]; then
echo "Today is neither month 1st, nor sunday."
fi

$ bash test1
Today is neither month 1st, nor sunday.

$ cat test2 
#!/bin/bash
Today_Date=$(date '+%d')
Today_Week=$(date '+%w')
if [[ 10#$Today_Date -ne 1 || $Today_Week -gt 0 ]]; then
echo "Today is neither month 1st, nor sunday."
fi

$ bash test2 
Today is neither month 1st, nor sunday.
Please help.

Last edited by cli; 06-07-2013 at 05:17 PM.
 
Old 06-07-2013, 05:24 PM   #4
mandyapenguin
Member
 
Registered: Nov 2011
Location: India
Distribution: RedHat, Cent OS, Fedora, Debian, Ubuntu
Posts: 106

Rep: Reputation: Disabled
Try
Code:
#!/bin/bash
Today_Date=$(date '+%e')
Today_Week=$(date '+%w')
if [[ $Today_Date -ne 1 && $Today_Week -gt 0 ]]; then
echo "Today is neither month 1st, nor sunday."
fi
Change the date to month 1st and also to Sunday, then try.
 
1 members found this post helpful.
Old 06-07-2013, 06:09 PM   #5
cli
Member
 
Registered: Apr 2013
Distribution: RedHat, Cent, Ubuntu
Posts: 80

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by mandyapenguin View Post
Try
Code:
#!/bin/bash
Today_Date=$(date '+%e')
Today_Week=$(date '+%w')
if [[ $Today_Date -ne 1 && $Today_Week -gt 0 ]]; then
echo "Today is neither month 1st, nor sunday."
fi
Change the date to month 1st and also to Sunday, then try.
Thank you very much mandyapenguin. You both solved the problem.
Thanks a lot to LinuxQuestions.Org
 
Old 06-09-2013, 06:08 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
Read up here for more detail on how bash treats leading zeroes, and how to handle them:

http://mywiki.wooledge.org/ArithmeticExpression
http://mywiki.wooledge.org/BashFAQ/018

Edit: BTW, you can combine your two date calls into one, like this:

Code:
read Today_Date Today_Week < <( date '+%e %w' )
Also, when using advanced shells like bash or ksh, it's recommended to use [[..]] for string/file tests, and ((..)) for numerical tests.

http://mywiki.wooledge.org/BashFAQ/031
http://mywiki.wooledge.org/ArithmeticExpression

Since these are numeric tests, you should be using:

Code:
if (( Today_Date != 1 && Today_Week > 0 )); then

Last edited by David the H.; 06-09-2013 at 06:14 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting: value too great for base (error token is "08") xsyntax Linux - General 5 09-24-2013 12:18 PM
[SOLVED] Script error: "syntax error near unexpected token 'then'" RyuuzakiMasato7 Linux - Server 18 06-20-2011 10:28 AM
[Bash] 09: value too great for base (error token is "09") Erhnam Programming 3 02-25-2005 05:25 AM


All times are GMT -5. The time now is 11:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration