Question about ksh "trap" and "select" statements

Govind N. Kamat kamat at uceng.UC.EDU
Mon May 8 07:05:13 AEST 1989


I had a couple of questions about the Korn shell...

> trap "continue" INT TSTP
> select i in a b c; do
> 	prog
> done
> ...more statements...

This is supposed to display a menu consisting of a, b and c, and then
print a prompt asking the user to pick one.  Now, if a keyboard
interrupt is generated while "prog" is being executed, the trap causes
control to be returned to the prompt, as it should.  However, if
generated at the prompt itself, the menu gets printed out one more
time, and the program is aborted immediately after that.

I would have expected, that either:
a)  The menu is printed out once more, followed by the input prompt --
similar to the behavior when a new-line is entered, OR, less likely,
b)  The select is quit, but without printing of the menu.  But, the
program is not aborted, and control passes to the next instruction.

Would anyone have any idea as to why this behavior?

Secondly, there seem to be only two possible actions for SIGTSTP in
the trap: the default, or ignore.  Associating it with an action like
"continue" as shown above causes it to be ignored.  If there are any
non built-in commands in the script, of course it doesn't make much
sense to stop those and leave the shell blocked.  But even if all
commands in the script are internal to the shell, the "continue" is
never generated with a TSTP.

Are these related to any "features" of ksh?  
Thanks for any comments.

-- 
Govind N. Kamat				College of Engineering
kamat at uceng.UC.EDU			University of Cincinnati
					Cincinnati, OH 45221, USA



More information about the Comp.unix.questions mailing list