zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: Somewhat unexpected results of {myfd}>&1 when noclobber set
Date: Sat, 09 Mar 2013 07:12:52 -0800	[thread overview]
Message-ID: <130309071252.ZM19892@torch.brasslantern.com> (raw)
In-Reply-To: <CAHYJk3SexAxWnKHSBWCnvcAu7RjC_Go6Sd1Uwn-QujvpYzrnvw@mail.gmail.com>

On Mar 9, 11:33am, Mikael Magnusson wrote:
}
} % bar=( 14 15 )
} % : {bar}>&1
} zsh: bad math expression: operator expected at `15'
} % echo $bar
} 16

This is clearly a bug.  Failing the math eval should either abort the
entire operation, or not print the warning.  I think the latter would
be considered the intended behavior, that is, bar does not contain a
descriptor so it simply gets assigned a new one by the redirection.

} % bar=foo
} % : {bar}>&1
} zsh: can't clobber parameter bar containing file descriptor 15
} % foo=
} % : {bar}>&1
} zsh: can't clobber parameter bar containing file descriptor 15
} % echo $bar
} 15

I can't reproduce that one.  For me, after unsetting foo or setting it
to empty, {bar}>&1 simply assigns a new descriptor to bar.

} (at this point bar somehow became of type "integer", i think after it
} was an array, so the earlier assignment bar=foo resolved foo to 15).

Variables to which descriptors are assigned by redirection are set to
integer type, even if their original type was something else.  Given
that I can't reproduce other parts of your steps, I can't say whether
this happened coincident with the spurious "bad math expression" or
somewhere else.

} I think it's at least not expected that this parameter is only subject
} to math evaluation if the clobber option is unset.

Just to clarify:  The statements

    setopt clobber
    bar=15
    : {bar}>&2

do NOT result in 2 being dup'd to 15, it results in 2 being dup'd to a
new descriptor and that new descriptor being assigned to bar.  The
value is *examined* only when noclobber, so whether it is also math-
evaluated is really beside the point.

The real question is whether math evaluation is applied when you do

    print something >&$bar

If $bar is not evaluated in that context, then it should not be in the
dup context either, but if it IS evaluated in that context, then it
should be treated consistently .  Guess what:

    integer bar=1+1
    print something >&$bar

DOES print to stderr, so I would argue that the current behavior is
the correct one (except for the spurious warning message).


  reply	other threads:[~2013-03-09 15:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-09 10:33 Mikael Magnusson
2013-03-09 15:12 ` Bart Schaefer [this message]
2013-03-10 12:11   ` Mikael Magnusson
2013-03-10 18:26     ` Bart Schaefer
2013-03-10 18:52   ` Peter Stephenson
2013-03-10 20:17     ` Peter Stephenson

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=130309071252.ZM19892@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --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).