Posts: 10
Joined: Tue Jan 10, 2012 1:56 pm

ksh93 bug - a small warning

Fri Dec 14, 2012 11:53 am

This is not rpi specific, it has existed in ksh93 for a long time, so more of a warning than anything else. Its recently cropped up with a script at work, much to my annoyance, adding one more reason to my "do not script in ksh" list, which is a shame because ksh88 is still great.

Firstly there is a documentation bug in ksh's man page. It states -
" If the -i option is present or if the shell input and output
are attached to a terminal (as told by tcgetattr(2)), then
this shell is interactive."
Use of -i option does (correctly) make the shell interactive, however "the shell input and output" should read "the shell input and error output".

The shell checks it is not running a script, and both stdin and stderr are ttys. It ignores stdout when determining whether it is or isn't interactive.

One of the upshots of this is, if in an interactive shell one redirects stderr using exec, job control for the shell will be broken from that point onwards.

Related to this is use of monitor mode in a ksh93 script, which in some ksh implemetations is needed to obtain the exit status from background commands. If one has any ksh script that uses "set -m" (set -o monitor), it's highly likely that they will not work as expected in ksh93.

Return to “General programming discussion”