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

Re: Why do I get a "bad filedescriptor" here? (redirection problem)



On 2006-10-25 at 10:52 +0200, Com MN PG P E B Consultant 3 wrote:
> zsh 4.0.7
> 
> $ ls >& -
> /bin/ls: write error: Bad file descriptor
> $ cat >&- <<<d
> cat: standard output: Bad file descriptor
> $ ls >/dev/null
> $ echo x >& -
> $ 
> 
> Why do I get a "bad file descriptor" in the first two cases?

Because you've closed it, so it's not available for writing.  Most tools
just assume that file descriptors 0, 1 and 2 are available for use and
will just write to stdout without checking, so they'll get errors and
complain like that when it's closed.

> Note that closing stdout with echo works fine, as does
> (of course) redirection of ls output to the bit bucket.

echo as a shell built-in is handling it gracefully, because zsh is
handling what you meant, not what you wrote.  Try it with /bin/echo and
you'll see it fail in the same way as the other commands.

If you want to discard output, redirect it to the bitbucket.

Regards,
-Phil



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