bug-bash
[Top][All Lists]
Advanced

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

Re: leading 0 inconsistence?


From: Greg Wooledge
Subject: Re: leading 0 inconsistence?
Date: Mon, 14 Feb 2011 08:51:13 -0500
User-agent: Mutt/1.4.2.3i

On Sat, Feb 12, 2011 at 11:57:08AM +0100, Ralf Goertz wrote:
> > if [ $((i)) -lt 9 ] ; then echo ok; fi
> bash: 08: value too great for base (error token is "08")
> 
> Why is 08 not tried to be interpreted as octal when *numerically* compared
> using test?

s/not // in your question, I assume.

Because the $((...)) bit is done first, without any knowledge that there
is a [ command around it.

If your i variable is coming from a source that may or may not include
leading zeroes (such as date(1)) then you have two choices:

 1) Strip the leading zeroes.
 2) Use 10#$i inside the arithmetic context to force base-10 interpretation.



reply via email to

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