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
2

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

|improve this answer|||||
  • It seems my scripts use eg. the /dev/stdout as a parameter to a function. Thus not only redirects. This doesn't work as a function parameter, does it? – Yuri Jan 18 '18 at 15:12
  • Can you provide an example? (in your question) – Gerard H. Pille Jan 18 '18 at 15:38
  • What does black_box_binary do with its third parameter? – Gerard H. Pille Jan 18 '18 at 18:19
  • It seems it prints its protocol/log to the file specified by the parameter. So normally it should output the protocol to the standard output. – Yuri Jan 18 '18 at 20:23
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.

|improve this answer|||||
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.