Bug #874
closedsh: fd redirections
0%
Description
Hi,
I was testing a few things, and I was wondering if that behavior is normal:
$ exec 3>&1
$ echo toto >&3
toto
$ echo toto > /dev/fd/3
toto
$ exec 3>&-
$ echo toto >&3
toto
$ echo toto > /dev/fd/3
cannot create /dev/fd/3: Bad file descriptor
Why is >&3 ignores the redirection, but not /dev/fd/3? It seems to me
like a bug.
SR
Updated by dillon about 17 years ago
:Hi,
:
:I was testing a few things, and I was wondering if that behavior is normal:
:
:$ exec 3>&1
:$ echo toto >&3
:toto
:$ echo toto > /dev/fd/3
:toto
:$ exec 3>&-
:$ echo toto >&3
:toto
:$ echo toto > /dev/fd/3
:cannot create /dev/fd/3: Bad file descriptor
:
:Why is >&3 ignores the redirection, but not /dev/fd/3? It seems to me
:like a bug.
:
:SR
I think the last part is working as it should. You close descriptor 3
with the 'exec 3>&-' line. An echo that dup's to descriptor 3 ... that's
only a temporary dup for just that command, so descriptor 3 shouldn't
exist afterwords, and it doesn't.
I'm not sure why descriptor 3 exists in the first part of your script,
your original exec dup's descriptor 3 to descriptor 1. Descriptor 3
probably doesn't exist at that point so it probably wound up not changing
descriptor 1 at all, and maybe that confused /bin/sh when you did the >&3
later on and caused /bin/sh to fail to close the redirected descriptor.
-Matt
Matthew Dillon
<dillon@backplane.com>
Updated by stephane.russell about 17 years ago
It seems "exec 3>&1" is supposed to open descriptor 3 when it's closed.
I made some tests on both sh and ksh on an AIX, on a Solaris and on
DFBSD/mksh. They all behave this way:
Updated by pavalos almost 13 years ago
- Description updated (diff)
- Status changed from New to Closed
- Assignee deleted (
0)
This should work correctly now. Please reopen if you don't agree.