18

An answer I gave to a question, and the comments to it, had me read the POSIX Conformance section of the Base Definitions to figure out whether /dev/stdin, /dev/stdout and /dev/stderr were actually needed for conformance to the POSIX standard.

It turns out they are not:

The system may provide non-standard extensions. These are features not required by POSIX.1-2008 and may include, but are not limited to: [...] Additional character special files with special properties (for example, /dev/stdin, /dev/stdout, and /dev/stderr)

As far as I can find, this is the only mentioning of these files in the standard.

I have access to only one "system" (environment, really) which does not implement them, and that's MinGW on Windows (no /dev at all as far as I can see). As far as I know, all the free Unices have them, and so does Cygwin, Windows' new Linux environment and Darwin/macOS.

I'm not well versed with the commercial Unices though.

Is there a POSIX system, Unix, or a Unix-like environment of some description, alive today, that does not implement /dev/stdin, /dev/stdout, and /dev/stderr as files in the filesystem?

Kusalananda
  • 333,661
  • 3
  • 4
    Also related: http://unix.stackexchange.com/questions/36403/portability-of-dev-stdout - this provides a list of platforms where it allegedly does not work in csh (csh being mainly relevant as an example of a shell other than bash, which may implement special handling for these names). – Random832 Jan 19 '17 at 18:23
  • @MarkPlotnick Thanks. Yes, it's somewhat related, but I'm interested in the availability of /dev/std{in,out,err} files rather than the availability of the /dev/fd and /proc hierarchies. – Kusalananda Jan 21 '17 at 18:08
  • @Random832 This is interesting, but it's a shame that Ola's answer doesn't include what he means by "works". As some utilities and shells apparently simulate these files, it would be nice to know what the test was... – Kusalananda Jan 21 '17 at 18:12

2 Answers2

6

Is there a POSIX system, Unix, or a Unix-like environment of some description, alive today, that does not implement /dev/stdin, /dev/stdout, and /dev/stderr as files in the filesystem?

Yes, at least per my example system below.

I'm not an expert in this system by any means; however, AIX 6.1, which wikipedia claims is:

one of five commercial operating systems that have versions certified to The Open Group's UNIX 03 standard (https://en.wikipedia.org/wiki/IBM_AIX)

does not appear to implement those file descriptors in the installation I have access to. As you can see, if using bash, it will behave as if they did exist for the purposes of redirection:

$ uname -s
AIX
$ echo $SHELL
/usr/bin/ksh
$ ls -al /dev/stdin
ls: 0653-341 The file /dev/stdin does not exist.
$ ls -al /dev/stdout
ls: 0653-341 The file /dev/stdout does not exist.
$ ls -al /dev/stderr
ls: 0653-341 The file /dev/stderr does not exist.
$ echo foo >/dev/stderr
The file access permissions do not allow the specified action.
ksh: /dev/stderr: 0403-005 Cannot create the specified file.
$ bash
bash-4.2$ ls /dev/stderr
ls: 0653-341 The file /dev/stderr does not exist.
bash-4.2$ echo foo >/dev/stderr
foo

As other commenters have mentioned, the following questions provide some interesting information as well:

Steven D
  • 46,160
3

I'm posting well after the initial posts but thought I'd add this comment for future viewers.

I get the same results writing to /dev/stdout as above on an AIX 6.1 system, but on an AIX 7.1 system it works as expected, so it looks support for /dev/stdout was added.

AIX 6.1 (ksh93)

echo "Hello" > /dev/stdout                                            
ksh93: /dev/stdout: cannot create.
[The file access permissions do not allow the specified action.].

AIX 7.1 (ksh93)

echo "Hello" > /dev/stdout
Hello
Scavenger
  • 145
  • What about /dev/stdin? – jnovack Sep 09 '19 at 19:33
  • I don't know about aix, but that test is lousy: some shells implement /dev/stdout as a fake file hack if the OS doesn't support it. You should demonstrate that by passing the path to an external program: cat /dev/stdin. –  Feb 06 '20 at 08:21