zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: zsh-workers@zsh.org
Subject: [BUG] emulate sh: arith assignment assigns variable type
Date: Fri, 01 Jan 2016 21:03:33 +0100	[thread overview]
Message-ID: <5686DB95.2090602@inlv.org> (raw)

When an assignment is done to an unset variable using an arithmetic
expression, zsh assigns a numerical or arithmetic type to that variable,
causing subsequent normal shell assignments to be interpreted as
arithmetic expressions.

This causes an incompatibility with other shells under 'emulate sh',
because the POSIX shell is supposed to be a typeless language. In sh
emulation mode, arithmetic assignment should not assign a variable type.

Steps to reproduce:

$ emulate sh
$ X=a:b:c
$ : $((X=1))	# no type assignment as variable was already et
$ X=a:b:c
$ unset X
$ : $((X=1))	# variable now restricted to arith expressions
$ X=a:b:c
zsh: bad math expression: ':' without '?'

Expected behaviour: the last assignment should succeed in sh emulation
mode (and does on all other shells).

Confirmed in zsh 4.1.1 through current.

Thanks, and happy new year.

- Martijn


             reply	other threads:[~2016-01-01 20:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-01 20:03 Martijn Dekker [this message]
2016-01-02 18:11 ` Peter Stephenson
2016-01-02 19:37   ` Mikael Magnusson
2016-01-02 20:46   ` Bart Schaefer
2016-01-02 21:12     ` Peter Stephenson
2016-01-13  3:13   ` Martijn Dekker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5686DB95.2090602@inlv.org \
    --to=martijn@inlv.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).