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
- X-seq: zsh-users 14100
- From: Peter Stephenson <pws@xxxxxxx>
- To: "Tristan TERPELLE" <tristan.terpelle@xxxxxxxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Subject: Re: zsh in ksh emulation mode: typeset -i "allows" string as variable value
- Date: Wed, 06 May 2009 13:34:01 +0100
- In-reply-to: <38D4FA2BB99A674BADDED237051D97A70AC9845E@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <38D4FA2BB99A674BADDED237051D97A70AC9845E@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
"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