procmail
[Top] [All Lists]

Re: Fun With Shells (Part 2) (fwd)

1997-07-11 12:28:00
On Fri, 11 Jul 1997, Chris Bidmead wrote:

On Fri, 11 Jul 97 I (Chris Bidmead) wrote:

From the man pages:

    "Constants with a leading 0 are interpreted as octal numbers."

Blast!  I suppose Mr Posix is to blame for this, er, useful refinement...

The man pages seem to suggest that something like

bash> let N=[10]016

....might force the number to base10, but this doesn't work --  
"[10]016" is rejected as an "error token".


No shell aficionado here but you might try (I am using bash
version 1.14.6(1)):

bash:~$ let N=10#055
bash:~$ echo $N
55

In "Learning the bash Shell" from O'Reilly & Associates, (which
I just started reading) it says, "let doesn't create a variable
of type integer, it only causes the expression following the
assignment to be interpreted as an arithmetic one."

This would lead me to believe that the same result could be
achieved by simply doing:

bash:~$ let N=55 

If you assign the value to $N using either of these methods, and
then do "declare", (which lists all the environment variables)
you will in each case find a line "N=55".

If you actually require that $N hold the string "055", use
"declare" rather than "let".

bash:~$ declare N=055
bash:~$ echo $N
055

-- 
Jim Irwin <jirwin(_at_)mail(_dot_)netshop(_dot_)net>
running (..um..walking) Linux 2.0.30


<Prev in Thread] Current Thread [Next in Thread>