Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: f() { ...; } > file
- X-seq: zsh-workers 26035
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Subject: Re: f() { ...; } > file
- Date: Thu, 13 Nov 2008 14:25:06 +0000
- 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 Wed, Nov 05, 2008 at 09:20:36PM +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.
>
> It's OK when declaring the function as
>
> foo() echo a > file
> or
> foo() (echo a) > file
>
> instead of
>
> foo() { echo a; } > file
[...]
Interestingly, foo() > file { echo a; } works:
~$ bash -c 'f() { echo a; } > /dev/null; declare -f'
f ()
{
echo a
} > /dev/null
~$ ksh -c 'f() { echo a; } > /dev/null; typeset -f'
f() { echo a; } > /dev/null;% ~$ zsh -c 'f() { echo a; } > /dev/null; typeset -f'
f () {
echo a
}
~$ zsh -c 'f() > /dev/null { echo a; }; typeset -f'
f () {
{
echo a
} > /dev/null
}
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author