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

Re: zsh in ksh emulation mode: typeset -i "allows" string as variable value



"Tristan TERPELLE" wrote:
> We're running zsh in ksh emulation. It has come to our attention that
> it's possible to assign a non-integer value to a variable defined as
> integer with "typeset -i" (or with "integer").
> 
> After assigning a string to an integer variable, the exit code is 0. The
> new value of the variable is 0 aswell.
> 
> On HP-UX's ksh, however, such an operation isn't permitted resulting in
> an error message and an exit code of 1.
> 
> Is this normal behaviour for zsh or a bug? Can this behaviour be changed
> through zsh' options?

What happens in zsh is that assignments to an integer (or other numeric)
variable are subject to expansion, i.e. something like "var=five" is
equivalent to (( var = five )) if var has been suitably declared, so
that the value of $five is retrieved, probably numerically equivalent to
0.

This is normal zsh behaviour, but not very convenient for compatibility.
I don't think it would be hard to do it differently with a compatibility
option, but there's no simple workaround that I can see at the moment.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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