osdir.com
mailing list archive F.A.Q. -since 2001!



Subject: Re: Arithmetic expansion peculiarity - msg#00056

List: bug-bash-gnu

Mail Archive Navigation:
by Date: Prev Next Date Index by Thread: Prev Next Thread Index

On Thursday 13 Jan 2011 21:11:07 Joe Lightning wrote:

> Description:
> Bash doesn't like leading zeros in arithmetic expansion.
>
> Repeat-By:
> echo $(( 09 - 1 ))

It's all documented. Numbers with leading zeros are treated as octal. In your
case, you can work around that by either removing the leading zeros, or
explicitly telling bash that the number is in base 10:

$ echo $(( 10#09 - 1 ))
8

--
D.

Thread at a glance:

Previous Message by Date:

Arithmetic expansion peculiarity

Configuration Information [Automatically generated, do not change]: Machine: i686 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -march=i686 -mtune=generic -O2 -pipe -DDEFAULT_PATH_VALUE='/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin' -DSTANDARD_UTILS_PATH='/usr/bin:/bin:/usr/sbin:/sbin' -DSYS_BASHRC='/etc/bash.bashrc' -DSYS_BASH_LOGOUT='/etc/bash.bash_logout' uname output: Linux joelightning.com 2.6.36-ARCH #1 SMP PREEMPT Sun Dec 12 08:44:00 UTC 2010 i686 Intel(R) Celeron(TM) CPU 1100MHz GenuineIntel GNU/Linux Machine Type: i686-pc-linux-gnu Bash Version: 4.1 Patch Level: 9 Release Status: release Description: Bash doesn't like leading zeros in arithmetic expansion. Repeat-By: echo $(( 09 - 1 )) signature.asc Description: This is a digitally signed message part

Next Message by Date:

Re: Arithmetic expansion peculiarity

Joe Lightning wrote: > Description: > Bash doesn't like leading zeros in arithmetic expansion. > > Repeat-By: > echo $(( 09 - 1 )) This is bash FAQ E8. http://www.faqs.org/faqs/unix-faq/shell/bash/ Leading zeros denote octal. In octal the valid digits are 0-7 with 8 and 9 outside of the octal range. Bob

Previous Message by Thread:

Arithmetic expansion peculiarity

Configuration Information [Automatically generated, do not change]: Machine: i686 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -march=i686 -mtune=generic -O2 -pipe -DDEFAULT_PATH_VALUE='/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin' -DSTANDARD_UTILS_PATH='/usr/bin:/bin:/usr/sbin:/sbin' -DSYS_BASHRC='/etc/bash.bashrc' -DSYS_BASH_LOGOUT='/etc/bash.bash_logout' uname output: Linux joelightning.com 2.6.36-ARCH #1 SMP PREEMPT Sun Dec 12 08:44:00 UTC 2010 i686 Intel(R) Celeron(TM) CPU 1100MHz GenuineIntel GNU/Linux Machine Type: i686-pc-linux-gnu Bash Version: 4.1 Patch Level: 9 Release Status: release Description: Bash doesn't like leading zeros in arithmetic expansion. Repeat-By: echo $(( 09 - 1 )) signature.asc Description: This is a digitally signed message part

Next Message by Thread:

Re: Arithmetic expansion peculiarity

Joe Lightning wrote: > Description: > Bash doesn't like leading zeros in arithmetic expansion. > > Repeat-By: > echo $(( 09 - 1 )) This is bash FAQ E8. http://www.faqs.org/faqs/unix-faq/shell/bash/ Leading zeros denote octal. In octal the valid digits are 0-7 with 8 and 9 outside of the octal range. Bob
blog comments powered by Disqus

Home | News | Sitemap | FAQ | advertise | OSDir is an Inevitable website. GBiz is too!