Capturing a ^C to break out of a script?
m.w.chang
mwchang
Mon May 17 11:33:56 PDT 2004
from some old messages in caldera linux-uses. maybe we can add to the
linux-sxs website.
**** by Eric Ratcliffe, Jan 1999
You'll probably have to put in a few stty lines in the script to disable
breaking. I've never done this, but I will bet that it works.
In the beginning of the script, have something like
stty -ignbrk
and at the end, have something like
stty -cbreak
Note that this method will defintely require some research; I have not done
it myself, so I guarantee there's something I'm missing. You did ask for
pointers, though. :)
**** by John Pinner, Jan 1999
You can do this with the shell built-in command trap.
Syntax is 'trap [command_string] signal'
where signal is the number (as defined in /usr/include/asm/signal.h) of
the signal to be trapped.
command_string is the command string to be executed when the trap is
taken, if null the trap will not be taken.
if command_string is omitted the trap will be restored to the default
so....
trap "echo Goodbye" 0
will echo Goodbye when you logout (signal 0)
trap "" 2 3 will disable signals 2 and 3 ( interrupt and quit ) # This
what you want ?
trap 2 3 will restore the signals to the default action
Hope this helps,
James McDonald wrote:
> Umm I was wondering if there is anyway of breaking out of a script by
> capturing the CTRL+C combination and completey exiting the script I am
> running the following and if the login fails it still trys to go through the
> entire 'for in do'
>
> Thanks
>
> #!/bin/sh
> # login to cvs
>
> me=$0
>
> export CVSROOT=:pserver:guest at cvs.openoffice.org:/cvs
>
>
> cvs login
>
> for i in `echo *`
>
> do
> echo Checking Out $i
> cvs -z3 co -PA $i
> done
>
> cvs logout
>
> echo "$0 Done"
>
--
Linux 2.4.18
up 36 days, 1:00, 0 users, load average: 1.00, 1.00, 1.00
Join us in news://news.hkpcug.org and http://www.linux-sxs.org
More information about the Linux-users
mailing list