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

Re: Somewhat unexpected results of {myfd}>&1 when noclobber set



On Sat, 09 Mar 2013 07:12:52 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 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.

I suppose so, it's consistent with

% setopt noclobber
% foo=fictional
% exec {foo}>&1
% print $foo
11

But I think Michael's right that to get that effect we don't want the
matheval at all --- we just want to see if foo contains an integer (it
looks like we also check if it's a previously opened fd after retrieving it).
We're only interested in whether foo has previously been set to an
actual descriptor, not to something that might in future evaluate to a
descriptor, which wouldn't make sense.  So if "foo=10+1" it's also not a
descriptor (can't be the result of a previous fd-open-and-assign-to-variable)  and so can be clobbered.

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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