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

f() { ...; } > file



Hiya,

$ 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

-- 
Stéphane



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