Re: Capturing a ^C to break out of a script?
On Wed, 26 Jun 2002 19:11:16 -0400 Kurt Wall [EMAIL PROTECTED] wrote: Also sprach James McDonald: 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 You should be able to use the trap builtin (if you're using bash). as well as sh and ksh/pdksh, which is as far as my shell use goes. I would expect csh/zsh/tcsh all have the capability. wish uses a 'bind' command to trap things (both real and virtual). Oddly, most people don't consider wish/tclsh when making 'shell' scripts. Too bad. Works great. -- ++===+ | Roger Oberholtzer | E-mail:[EMAIL PROTECTED] | | OPQ Systems AB | WWW: http://www.opq.se/ | | Erik Dahlbergsgatan 41-43 |Phone: Int + 46 8 314223 | | 115 32 Stockholm | Mobile: Int + 46 733 621657 | | Sweden | Fax: Int + 46 8 302602 | ++===+ ___ Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL.
Capturing a ^C to break out of a script?
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:[EMAIL PROTECTED]:/cvs cvs login for i in `echo *` do echo Checking Out $i cvs -z3 co -PA $i done cvs logout echo $0 Done -- James McDonald MCSE (Windows 2000/NT4), CCNA, CCA, MCP + I Registered Linux User #209832 http://jamesmcd.dns2go.com (home) Red Hat Linux release 7.2 (Enigma) 8:44pm up 11:41, 7 users, load average: 0.28, 0.10, 0.03 ___ Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL.
Re: Capturing a ^C to break out of a script?
I am not sure just what you want to do. The ctrl-c key should be able to kill your program for you. If not, try ctrl-\. Usually, I use the or || construct if I need to test for the success of a command before I continue. eg: cvs login || exit 1 (I am not sure what cvs login is so this command may not work) You could also set up a trap, eg: trap CommandToProcessCntrl-c INT Joel On Wed, Jun 26, 2002 at 08:48:03PM +1000, 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:[EMAIL PROTECTED]:/cvs cvs login for i in `echo *` do echo Checking Out $i cvs -z3 co -PA $i done cvs logout echo $0 Done -- James McDonald MCSE (Windows 2000/NT4), CCNA, CCA, MCP + I Registered Linux User #209832 http://jamesmcd.dns2go.com (home) Red Hat Linux release 7.2 (Enigma) 8:44pm up 11:41, 7 users, load average: 0.28, 0.10, 0.03 ___ Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL. ___ Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL.
Re: Capturing a ^C to break out of a script?
I define a procedure that will be called. In this case, it prints a message and then calls my Exit procedure for a tidy exit: # # Catch program termination. # interrupt () { cat *EOF* ERROR: The backup was interrupted before it was complete. This means that you must re-do the backup or risk loosing the files. *EOF* Exit ${FAILURE} } trap interrupt 2 3 On Wed, 26 Jun 2002 20:48:03 +1000 James McDonald [EMAIL PROTECTED] 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:[EMAIL PROTECTED]:/cvs cvs login for i in `echo *` do echo Checking Out $i cvs -z3 co -PA $i done cvs logout echo $0 Done -- James McDonald MCSE (Windows 2000/NT4), CCNA, CCA, MCP + I Registered Linux User #209832 http://jamesmcd.dns2go.com (home) Red Hat Linux release 7.2 (Enigma) 8:44pm up 11:41, 7 users, load average: 0.28, 0.10, 0.03 ___ Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL. -- ++===+ | Roger Oberholtzer | E-mail:[EMAIL PROTECTED] | | OPQ Systems AB | WWW: http://www.opq.se/ | | Erik Dahlbergsgatan 41-43 |Phone: Int + 46 8 314223 | | 115 32 Stockholm | Mobile: Int + 46 733 621657 | | Sweden | Fax: Int + 46 8 302602 | ++===+ ___ Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL.