[TriLUG] BASH oddity
rick.denatale at gmail.com
Tue Feb 21 18:47:42 EST 2006
On 2/21/06, G.Wolfe Woodbury <ggw at wolves.durham.nc.us> wrote:
> On Tue, Feb 21, 2006 at 06:02:10PM -0500, Paul G. Szabady wrote:
> > That's what I thought, but other non-octal combinations work.
> > IE
> > [paul at at paul]$ declare -i dirx=88 ; echo $dirx
> > 88
> > [paul at at paul]$
> The leading '0' digit trigger the octal interpretation. There are
> special cases in the code for 09 but 08 seems to have escaped someone's
> notice. The library spec says that 08 should be correctly interpreted.
> might be worth filing a bug with your distributions bug site.
Not sure which library spec you're talking about, but bash seems to be
working as designed if it rejects a constant of 08, and if its
accepting 09 then THAT's a bug.
Bash on my Ubuntu/debian system doesn't like either 08 or 09 as an
arithmethic literal. And I don't believe that it should. Here's the
relevant paragraph from man bash:
Constants with a leading 0 are interpreted as octal numbers. A
leading 0x or 0X denotes hexadecimal. Otherwise, numbers take the
form [base#]n, where base is a decimal number between 2 and 64
representin the arithmetic base, and n is a number in that base. If
base# is omitted, then base 10 is used. The digits greater than
9 are represented by the lowercase letters, the uppercase letters, @,
and _, in that order. If base is less than or equal to 36, lowercase
and uppercase letters may be used inter$B!>(Bchangeably to represent
numbers between 10 and 35.
So here's a way to get around the problem:
rick at bill:~$ declare -i dirx=10#$(date +%V)
rick at bill:~$ echo $dirx
declare -i dirx=10#$(date +%V)
More information about the TriLUG