more unix jokes - /dev/null

Leo de Wit leo at philmds.UUCP
Thu Sep 22 06:00:53 AEST 1988


In article <8541 at smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <811 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:
>>>	command > /dev/null
>>    command >&-
>
>But that is not equivalent.  In particular, an error will occur when
>output is attempted to fd#1.

Yes, that would be the result to be expected, wouldn't it? The file
descriptor is closed, and cannot be accessed anymore. However, it seems
like the shell is doing something like redirecting to a /dev/null
device (who can comment on that one?), since the following program
behaved OK (look Ma, no core!):

----------------- s t a r t s   h e r e -----------------
/* iotest */
#include <stdio.h>

main()
{
	int i;

   for (i = 0; i < 3; i++) {
      printf("stdout: %d\n",i); fflush(stdout);
      fprintf(stderr,"stderr: %d\n",i); fflush(stderr); /* not really needed */
   }
}
----------------- e n d s       h e r e -----------------

$ iotest
stdout: 0
stderr: 0
stdout: 1
stderr: 1
stdout: 2
stderr: 2
$ iotest >&-
stderr: 0
stderr: 1
stderr: 2
$ iotest 2>&-
stdout: 0
stdout: 1
stdout: 2
$ iotest >&- 2>&-
$

So to me it seems possible after all...
                                         Leo.



More information about the Comp.bugs.4bsd.ucb-fixes mailing list