Re: Convert 08 to decimal 8
- From: Brian Mac <mcnamarabrian@xxxxxxxxx>
- Date: Wed, 12 Sep 2007 13:01:24 -0000
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.
.
- References:
- Convert 08 to decimal 8
- From: SiKing
- Convert 08 to decimal 8
- Prev by Date: Re: I am seeing a ? in the directory
- Next by Date: How can I insert a separator after each n-th sign in a line?
- Previous by thread: Re: Convert 08 to decimal 8
- Next by thread: Finding and copying unique files in a directory.
- Index(es):
Relevant Pages
|
|