bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: value too great for base (error token is "0008")


From: Eric Blake
Subject: Re: value too great for base (error token is "0008")
Date: Wed, 04 Nov 2009 06:32:45 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Greg Wooledge on 11/4/2009 6:23 AM:
> On the other hand, removing a single leading zero is not difficult:
> 
>   month=$(date +%m) month=${month#0}   # Removing leading 0

Not portable.  Assigning the same variable twice in the same statement has
different order of operations in some shells.  Use:

month=$(date +%m); month=${month#0}

instead.

>   next_month=$(( ($month == 12) ? 1 : $month+1 ))
> 
> Removing multiple leading zeroes, however, requires either a loop, or the
> use of extended globs.

Not true.  You can do it via POSIX and without a loop by using an
intermediate variable:

foo=00081
bar=${foo%%[!0]*}
foo=${foo#$bar}}

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrxgn0ACgkQ84KuGfSFAYDyCACg0suH5IFGv+4dOe5Bf3kyBExR
R20AoM+U/AP6tqrF0QpEEYWgvjfx2m+H
=aC1b
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]