Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: f() { ...; } > file
- X-seq: zsh-workers 26011
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Subject: Re: f() { ...; } > file
- Date: Wed, 5 Nov 2008 14:49:24 -0800
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=d200807; d=spodhuis.org; h=Received:Date:From:To:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; b=CmDRmkuU5GHi8f+0ihKPLTnvTnGaj+A72zUTx/ZqJDx4xH5kzya+FZfozjtrpLI5k9iCh6RLP0K6NJBKLN3ksNqMIk9Xw2AuX/Rk2MrVQA0be7X9VJo6mEK1BrA+zvACfDnNJbTI2IDEtDvGuM9k0lr+41aelSDL7fAJ8LbzNpo=;
- In-reply-to: <20081105212036.GA4698@xxxxxxxxxxxxxxx>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20081105212036.GA4698@xxxxxxxxxxxxxxx>
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).
Messages sorted by:
Reverse Date,
Date,
Thread,
Author