zsh-users
 help / color / mirror / code / Atom feed
* Why do I get a "bad filedescriptor" here? (redirection problem)
@ 2006-10-25  8:52 Com MN PG P E B Consultant 3
  2006-10-25 10:55 ` Phil Pennock
  0 siblings, 1 reply; 4+ messages in thread
From: Com MN PG P E B Consultant 3 @ 2006-10-25  8:52 UTC (permalink / raw)
  To: zsh-users Mailinglist

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?
Note that closing stdout with echo works fine, as does
(of course) redirection of ls output to the bit bucket.

And in case this matters:

$ type ls
ls is an alias for /bin/ls --almost-all --color --classify
$ type cat
cat is /bin/cat

Ronald
-- 
Ronald Fischer (phone +49-89-63676431)
mailto:mn-pg-p-e-b-consultant-3.com@siemens.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why do I get a "bad filedescriptor" here? (redirection problem)
  2006-10-25  8:52 Why do I get a "bad filedescriptor" here? (redirection problem) Com MN PG P E B Consultant 3
@ 2006-10-25 10:55 ` Phil Pennock
  2006-10-25 11:05   ` Com MN PG P E B Consultant 3
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Pennock @ 2006-10-25 10:55 UTC (permalink / raw)
  To: Com MN PG P E B Consultant 3; +Cc: zsh-users Mailinglist

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Why do I get a "bad filedescriptor" here? (redirection problem)
  2006-10-25 10:55 ` Phil Pennock
@ 2006-10-25 11:05   ` Com MN PG P E B Consultant 3
  2006-10-25 12:30     ` Phil Pennock
  0 siblings, 1 reply; 4+ messages in thread
From: Com MN PG P E B Consultant 3 @ 2006-10-25 11:05 UTC (permalink / raw)
  To: Phil Pennock; +Cc: zsh-users Mailinglist

> > 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.

I see! And I thought that >&- is just a short cut for >/dev/null !!!
Thank you for explaining this.

Ronald
-- 
Ronald Fischer (phone +49-89-63676431)
mailto:mn-pg-p-e-b-consultant-3.com@siemens.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why do I get a "bad filedescriptor" here? (redirection problem)
  2006-10-25 11:05   ` Com MN PG P E B Consultant 3
@ 2006-10-25 12:30     ` Phil Pennock
  0 siblings, 0 replies; 4+ messages in thread
From: Phil Pennock @ 2006-10-25 12:30 UTC (permalink / raw)
  To: Com MN PG P E B Consultant 3; +Cc: zsh-users Mailinglist

On 2006-10-25 at 13:05 +0200, Com MN PG P E B Consultant 3 wrote:
> I see! And I thought that >&- is just a short cut for >/dev/null !!!

zshmisc(1), section REDIRECTION, covers all of the options here.

-Phil


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-10-25 12:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-25  8:52 Why do I get a "bad filedescriptor" here? (redirection problem) Com MN PG P E B Consultant 3
2006-10-25 10:55 ` Phil Pennock
2006-10-25 11:05   ` Com MN PG P E B Consultant 3
2006-10-25 12:30     ` Phil Pennock

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).