LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-02-2012, 07:13 PM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 431
Blog Entries: 32

Rep: Reputation: 3
arithmetic error BUGGGGG


For a very looong looong time, I didn't realize why my script doesn't run at 8 and 9 am (no matter which timezone i was in) both US and Taiwan. Because I was too lazy to check and I can't wake up that early in the morning.
Code:
cookies="/tmp/pieayu.com_cookies.txt"

stime=$(($(date +%H)*10))
sleep $stime
.....
But now I realize why it doesn't:

Code:
# echo $((01*10))
10
# echo $((02*10))
20
# echo $((03*10))
30
# echo $((04*10))
40
# echo $((05*10))
50
# echo $((06*10))
60
# echo $((07*10))
70
# echo $((08*10))
-sh: arithmetic syntax error
# echo $((09*10))
-sh: arithmetic syntax error
# echo $((10*10))
100
# echo $((11*10))
110
# echo $((12*10))
120
# echo $((13*10))
130
# echo $((14*10))
140
# echo $((18*10))
180
# echo $((19*10))
190
# echo $((20*10))
200
# echo $((21*10))
210
Only when it is 08 and 09, the calculation doesn't work. I am pretty sure this is a bug, or else all 01-07 should not work as well, since the programmer intentionally designed for them to work, why do 08 and 09 don't?
If this is some binary related stuff not a bug, then let me know.
Thanks,
Ted

Last edited by ted_chou12; 11-02-2012 at 07:15 PM.
 
Old 11-02-2012, 07:53 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Numbers starting with a 0 are interpreted as being in octal. 8 and 9 are invalid octal numbers. Lose the leading 0 or specify the base.

Code:
~$ echo $((10#8*10))
80
 
1 members found this post helpful.
  


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
[SOLVED] Arithmetic (bc) within for loop januka Programming 3 10-22-2012 07:26 PM
[SOLVED] arithmetic in bash xeon123 Linux - Newbie 9 04-23-2011 09:39 AM
typeset arithmetic syntax error rosariop Linux - Newbie 7 10-13-2009 08:27 AM
swaret error "invalid arithmetic operator" Blackmeth Slackware 5 04-25-2007 11:14 AM
Bash arithmetic Blackout_08 Programming 2 06-08-2006 10:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:18 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
Open Source Consulting | Domain Registration