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
|