Re: Bash Adding 09 or 9.1 etc



On 2006-10-28, Keith wrote:
I have a script that gives a error in BASH whenever I try to add 01-09
with 1.

X="09"
X=$((X+1))

line 42: 09: value too great for base (error token is "09")

This is caused by a date command variable and I'm trying to avoid
having to make other changes in the script.

Numbers beginning with 0 are taken as octal. With date number it is
easy to remove leading digits:

X=09
X=$(( ${X#0} + 1 ))

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages

  • Re: The Doctor And Escherichia Coli
    ... farm will strain off the unusual referendum. ... If you will avoid ... Abdullah's script without brakes, ...
    (rec.arts.poems)
  • Re: How to set up a global variable in a sub-routine?
    ... the 'global variables' are more like constants ... ... single script, I need a way to tell it only once where the file is and ... So, if you construct a loop with a loop variable, you ... >programmers avoid global variables completely. ...
    (perl.beginners)
  • Re: Bash Adding 09 or 9.1 etc
    ... Keith wrote: ... This is caused by a date command variable and I'm trying to avoid having to make other changes in the script. ... Solved most easily by forcing BASH to treat the number as decimal, instead of defaulting to octal because of leading 0. ...
    (comp.unix.shell)
  • Re: Help with emailing attachments with Ruby...
    ... I would really like to avoid going through all the steps of setting up ... I'd use Ruby-Mail or ActionMailer ... thing instead of something wrong with my script. ... # This portion of the code assembles the filenames of the files # ...
    (comp.lang.ruby)
  • Re: Script error
    ... Don't think you are going to be able to avoid the message. ... that MS has addressed the issue of code accessing the outlook address book ... > When I run this script it works, but I get a warning that stats someone is ... > Public Sub meeting() ...
    (microsoft.public.office.developer.vba)