3

I've been porting a bunch of scripts on AIX 7.1. I got no prior experience with this Unix system.

The scripts were ran under /bin/sh and relied on /dev/stdout, /dev/stdin and /dev/stderr. These files are known to be non-standardized and the AIX 7.1 does not seem to implement them.

As I discovered the /proc VFS is present, so I tried to substitute the /dev/std{in|out|err} with /proc/$$/fd/{0|1|2}. This failed, since the descriptors are not links to a pts but a real char file devices with permissions 000 (c---------).

The /bin/bash is known to emulate many devices in /dev including /dev/std*. My limited experiments with switching to /bin/bash from /bin/sh and using /dev/std* were successful. However, switching & testing all the scripts to /bin/bash would be time consuming.


Question:

How to handle the standard IO files in AIX 7.1 under /bin/sh? Is employing eg. /dev/tty the way?

// Example of a call in one of the scripts to be ported:

# param_protocol parameter apparently needs a file representation of the stdout
black_box_binary param1=$value1 param2=$value2 param_protocol=/dev/stdout
Yuri
  • 458
  • Relating: https://unix.stackexchange.com/q/297019/117549 – Jeff Schaller Jan 18 '18 at 10:42
  • I would clarify that "standard IO" could mean "(POSIX)-defined standard" or "stdio, such as stdin, stdout, stderr". As https://unix.stackexchange.com/a/36448/117549 and https://unix.stackexchange.com/a/417996/117549 point out, POSIX has defined only certain I/O targets. – Jeff Schaller Jan 18 '18 at 14:23
  • @JeffSchaller By "standard IO" I mean any "pseudo device file" which could be used as a redirect and passed as a function parameter. – Yuri Jan 18 '18 at 15:31

2 Answers2

2

You can replace those files by reading from <&0 and writing to >&1 and >&2, ie. stdin, stdout and stderr respectively.

0

Could the files /dev/std{in,out,err} be just symlinks to /proc/$$/fd/{0,1,2}? See "Standard error and other output redirection" for background information. However, according a former thread here, the Portability of “> /dev/stdout” seems to be shell dependent.

U880D
  • 1,146
  • 1
    No, on AIX 7.1 they are not symlinks. I can tell this seems to be common on Linux or cygwin, but not on AIX. – Yuri Jan 18 '18 at 15:14