|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Search this Thread |
|
#1
|
|||
|
|||
|
Disabling ctrl-Z key inside shell script
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 |
| Sponsored Links | ||
|
|
|
#2
|
||||
|
||||
|
See Vino's suggestion below (sorry, I was in a rush and in the middle of this and real work)
Last edited by RTM; 09-21-2005 at 08:38 AM.. |
|
#3
|
||||
|
||||
|
Quote:
Code:
trap "echo "Ctrl-Z key disabled" SIGTSTP From solaris signal primer we have Code:
SIGTSTP 24 Stop Stop (job control, e.g., ^z)) And from my linux machine Code:
$ kill -l SIGTSTP 20 $ kill -l 20 TSTP $ kill -l TSTP 20 $ kill -l 24 XCPU vino Last edited by vino; 09-21-2005 at 08:34 AM.. |
|
#4
|
||||
|
||||
|
Tried the following on Solaris (2.6 and 8) Code:
#!/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. |
|
#5
|
||||
|
||||
|
Tried this on linux and it worked. Code:
#!/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 Code:
./rtm.ksh[3]: trap: bad signal SIGTSTP And for 24, Code:
$ ./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 |
|
#6
|
||||
|
||||
|
TSTP worked on solaris.
|
|
#7
|
||||
|
||||
|
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: Quote:
I can only curse the darkness. I don't have a candle to light. Sorry. |
| Sponsored Links | ||
|
|
![]() |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to run an SQL script inside a shell | stevefox | Shell Programming and Scripting | 1 | 06-15-2006 10:11 PM |
| ftp files inside a shell script | matrix1067 | Shell Programming and Scripting | 5 | 02-07-2006 04:31 PM |
| How to run unix commands in a new shell inside a shell script? | hkapil | Shell Programming and Scripting | 2 | 01-04-2006 05:56 AM |
| Disable ctrl-c,ctrl-d,ctrl-d in ksh script | wtofu | AIX | 6 | 06-29-2005 04:41 PM |
| Using tar inside a shell script | kas7225 | Shell Programming and Scripting | 2 | 05-19-2005 11:06 PM |