Hi
I have tried to disable the CTRL-Z key inside a shell(sh) script using the command trap "`echo "Ctrl-Z key disabled"`" 20But I am not able to exit from the script after pressing CTRL-Z key.
How to proceed this? Need reply soon
See Vino's suggestion below (sorry, I was in a rush and in the middle of this and real work)
Wouldn't this be better off ?
trap "echo "Ctrl-Z key disabled" SIGTSTP
we have
SIGTSTP 24 Stop Stop (job control, e.g., ^z))
And from my linux machine
$ kill -l SIGTSTP
20
$ kill -l 20
TSTP
$ kill -l TSTP
20
$ kill -l 24
XCPU
vino
Tried the following on Solaris (2.6 and 8)
#!/bin/ksh
trap "" SIGTSTP
echo "try it - should not work"
sleep 15
trap - SIGTSTP
exit
It doesn't work - still allows Control-Z where if I change SIGTSTP to 24, it works. Tried under /bin/sh also.
Tried this on linux and it worked.
#!/bin/ksh
trap "" TSTP
echo "try it - should not work"
sleep 15
trap - TSTP
exit
signal 24 and SIGTSTP did not work.
It didnt recognize SIGTSTP. Gave me
./rtm.ksh[3]: trap: bad signal SIGTSTP
And for 24,
$ ./rtm.ksh
try it - should not work
[1] + Stopped ./rtm.ksh
$ fg
./rtm.ksh
I guess the op has to make the decision for the signal number to be used.
vino
TSTP worked on solaris.
Signals in a shell script become very complex very fast. Notice that the OP complained about using:
trap "`echo "Ctrl-Z key disabled"`" 20
Using the correct quoting is not any better:
trap "echo Cntl-Z key disabled" 20
You guys are proposing:
trap "" 20
which works fine. Whole different stretch of road. Try your scripts using the above trap statement. When you get tried of waiting for them, open another window, locate that sleep process, and do a "kill -CONT" to it.
Control Z is usually the SUSP character. Typing the SUSP characters sends SIGTSTP to all processes in the terminal's foreground process group. To disable control Z, the command is:
stty susp ^-
All of the posts here deal with catching or ignoring the TSTP signal, not disabling Control Z. Remember that shell scripts are collections of processes. The shell uses fork() and exec () to run the sleep program. From the exec man page:
So when TSTP is ignored, it stays ignored during the execution of the sleep process. But if it was caugth, it goes back to the default action which is to suspend the process. This is bad enough, but what's more, ksh has some bug involving caught job control signals. ksh has it own internal routine to catch those signals. It gets run instead of the specified command. So you don't even get the the message echoed.
I can only curse the darkness. I don't have a candle to light. Sorry.
At least you explained some of the strange things I was seeing.
Hi All
Sorry ,I forgot to tell one thing what i did inside the Shell script.Inside that script using vim/vi EDITOR i am opening a file.Till i finishes the editing work,if i press ctrl-C,ctrl-D,ctrl-Z key it should not close.I am able to disable the signals.But When i press CTRL-Z ,I am not able to exit from the vim editor.
PLease help me to resolve this problem.
If you are still within vi/vim after Ctrl-Z has been issued, then use Ctrl-Q to resume normal mode.
If vi/vim went into background, then use fg
vino
Hi Every body,
I want disable Control+C inside the script.How can I do this with trap command? Can anybody help me with correct syntax.
This is working fine in Solaris
trap "" 2 3 24
echo" Try to press Contrl+Z and see"
sleep 20
NB:- 24 is the code for Contrl+Z(SIGTSTP)
Mohammed Yoonus.S.M