zsh-workers
 help / color / mirror / code / Atom feed
From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: f() { ...; } > file
Date: Wed, 5 Nov 2008 14:49:24 -0800	[thread overview]
Message-ID: <20081105224924.GA11319@redoubt.spodhuis.org> (raw)
In-Reply-To: <20081105212036.GA4698@sc.homeunix.net>

On 2008-11-05 at 21:20 +0000, Stephane Chazelas wrote:
> $ bash -c 'foo() { echo a >&3; } 3>&1; foo'
> a
> $ ksh -c 'foo() { echo a >&3; } 3>&1; foo'
> a
> $ zsh -c 'foo() { echo a >&3; } 3>&1; foo'
> foo: 3: bad file descriptor
> $ ARGV0=sh zsh -c 'foo() { command echo a >&3; } 3>&1; foo'
> foo: 3: bad file descriptor
> 
> It looks like zsh evaluates the redirection at the time the
> function is defined rather than when it is called.

Back to front.

I think that you're misunderstanding what bash et al are doing.  They're
not deferring the redirection, they're resolving the redirection at
definition time so that it remains bound to stdout.

% bash -c 'foo() { echo a >&3; } 3>&1; exec >/dev/null; foo'
% bash -c 'foo() { echo a >&3; } 3>&1; foo'                 
a
% ksh -c 'foo() { echo a >&3; } 3>&1; foo'
a
% ksh -c 'foo() { echo a >&3; } 3>&1; exec >/dev/null; foo'
% ksh -c 'echo $KSH_VERSION'
@(#)PD KSH v5.2.14.2 99/07/13.2
% ksh93 -c 'foo() { echo a >&3; } 3>&1; exec >/dev/null; foo'
% ksh93 -c 'foo() { echo a >&3; } 3>&1; foo'                 
a
% ksh93 -c 'echo $KSH_VERSION'              
Version M 93t 2008-07-25

Whereas zsh defers evaluating the file-descriptor:
% zsh -c 'foo() { echo a >&3; } 3>&1; exec >/dev/null; foo 3>&2'
a
%

(There might be a mistake in my analysis; collapsing into head-cold,
 mind fuzzy, not diagnosing the shell problem further).


  reply	other threads:[~2008-11-05 22:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-05 21:20 Stephane Chazelas
2008-11-05 22:49 ` Phil Pennock [this message]
2008-11-06 14:38   ` Stephane Chazelas
2008-11-13 14:25 ` Stephane Chazelas
2008-11-13 14:42 ` [PATCH] " Stephane Chazelas
2008-11-13 14:52   ` Peter Stephenson
2008-11-13 15:03     ` Stephane Chazelas
2008-11-13 15:13       ` Stephane Chazelas
2008-11-13 15:27         ` Peter Stephenson
2008-11-13 14:55   ` Stephane Chazelas

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=20081105224924.GA11319@redoubt.spodhuis.org \
    --to=zsh-workers+phil.pennock@spodhuis.org \
    --cc=zsh-workers@sunsite.dk \
    /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).