LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-08-2006, 09:12 PM   #1
Blackout_08
Member
 
Registered: Jan 2004
Posts: 35

Rep: Reputation: 15
Bash arithmetic


I have this

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

Im using bin/bash. I need to be able to do this statement. It only does it when the last digit is 8-9. Help please
 
Old 06-08-2006, 10:04 PM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
Yeah, this is because the number starts with 0.
In bash every number that starts with 0 is considered octal (having 8 as a base) and not decimal.

SO you cannot have a number starting with 0 and containing the digits 8 and 9 inside

Last edited by perfect_circle; 06-08-2006 at 10:11 PM.
 
Old 06-08-2006, 10:37 PM   #3
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
You may strip the leading zeros, like this for example:
Code:
skalkoto@darkstar:~$ number=000657999
skalkoto@darkstar:~$ without_zero=$(echo $number |sed 's/0*//')
skalkoto@darkstar:~$ echo "$without_zero"
657999
skalkoto@darkstar:~$
or use bc instead:
Code:
skalkoto@darkstar:~$ echo "0006999 -1" | bc
6998
skalkoto@darkstar:~$
 
  


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
simple arithmetic in bash gfrair Linux - Newbie 9 03-16-2005 02:09 PM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM
Bash, non-integers and arithmetic causticmtl Programming 5 07-16-2003 09:15 AM
Basic Java arithmetic question chr15t0 Programming 2 07-05-2003 01:32 PM
arithmetic operators in Kylix3 (C++) herbie_52 Programming 2 05-23-2003 07:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:15 AM.

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