Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: test if a parameter is numeric



On Feb 10,  8:35am, Stephane Chazelas wrote:
} Subject: Re: test if a parameter is numeric
}
} On Fri, Feb 09, 2007 at 06:29:38PM -0800, Bart Schaefer wrote:
} > On Feb 9,  5:05pm, zzapper wrote:
} > }
} > } I just want to test if a parameter is numeric
} 
} I was under the impression that zzapper was looking for
} something to match *one* *decimal* digit though.

He said "numeric", but you may be right.
 
} By the way, are those normal:
} 
} $ echo $((40#^))
} 39
} 
} (given that ^ is also an arithmetic operator)?

% typeset -i 40 x
% x=39
% echo $x
40#^

Zsh is choosing "^" to represent 39 in base 40 because carat is the 29th
ASCII character after capital A, so the base 40 "digits" are
    0123456789ABC...XYZ[\]^

Some pretty strange stuff happens with bases larger than 200 where the
available range of "digits" runs out.  There should probably at least be
a warning about that somewhere.

There's definitely some other funny parsing going on here:

% echo $((##v)) 
118
% echo $((##0))
48
% echo $((##v - ##0))
70
% echo $((##^))      
94
% echo $((##^ - ##0))
-48
% echo $(((##v) - (##0)))    
70
% echo $(((##^) - (##0)))
zsh: ')' expected
% echo $[ $((##^)) - $((##0)) ]
46

} $ echo $((02#11))
} 3
} $ setopt octalzeroes
} $ echo $((02#11))
} zsh: bad math expression: operator expected at `#11'
} $
} 
} -- 
} Stéphane
}-- End of excerpt from Stephane Chazelas




Messages sorted by: Reverse Date, Date, Thread, Author