Re: Convert 08 to decimal 8



hi SiKing,

i know you specifically mentioned you would like to do this using the
bash shell. i'm not sure how using bash (others have explained much
better than i) but in korn shell you could use typeset:

$ typeset -LZ num=08
$ print $num
8

however, keep in mind you will run into the same issue where the
number 0 is stored as an empty string.

hope this helps,
brian

On Sep 7, 10:10 am, SiKing <nos...@xxxxxxxxxxxxx> wrote:
Hi all,

I am running this under bash 3.1.

I have two variables that each contain a number, which I need to compare for
equality. Unfortunately, sometimes, the number also contains leading zeros - I
need 8 to be equal to 08, for example.
I tried fixing it with 'let var+=0', but (quoted from the manual):
Constants with a leading 0 are interpreted as octal numbers. Otherwise, numbers
take the form [base#]n, where base is a decimal number between 2 and 64
representing the arithmetic base, and n is a number in that base. If base# is
omitted, then base 10 is used.

I can't seem to able to get this syntax to work. All of the following give me
syntax errors.
a=08
echo $(( $a + 0 ))
echo $(( []$a + 0 ))
echo $(( [10]$a + 0 ))
echo $(( [10#]$a + 0 ))

What is the secret formula?
Thank You.


.



Relevant Pages

  • Re: Python or 4NT? With a question or two about popen()
    ... the bash shell is really well suited for running ... Be aware though that bash syntax is really ... > I have a bunch of command line tests that I need to automate. ... > Homer Simpson: But every time I learn something new, ...
    (comp.lang.python)
  • Re: Convert Bash shell script to Korn shell script
    ... > The following bash script works fine to delete all files that are ... To execute this script, ... Start a bash shell: ... run the command "which find" ...
    (comp.unix.shell)
  • Re: Text over multiple lines
    ... > Write a Python script. ... you need my patched Bash which can be found at ... > You need to patch the Bash shell, ...
    (comp.lang.python)
  • Mangled 9.1 system
    ... I discovered that any bash shell ... The X interface seems to still work - but any xterm opened just hangs ... - but still bash hangs with no prompt. ...
    (alt.os.linux.suse)
  • Re: Bash examples and exercises book
    ... I found "Learning the Bash Shell" pretty usefull. ... Depends on your background I suppose, if you already have some scripting ... book with examples and exercises. ...
    (comp.unix.shell)