Ctrl-C untrap?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ctrl-C untrap?
# 1  
Old 05-10-2015
Ctrl-C untrap?

Hi guys...

I know how to trap Ctrl-C, that is easy and I have even done it obfuscated...

However once the trapping is enbaled how can the trapped Ctrl-C be returned to normal again? Google is not my friend here...

Reason, the recent Scope upload will hang awaiting a signal in EXT TRIG mode and Ctrl-C would be a good way of escaping this section without stopping the program completely...

TIA...
# 2  
Old 05-10-2015
Hi Barry, try:
Code:
trap - SIGINT


Last edited by Scrutinizer; 05-10-2015 at 08:57 AM..
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 3  
Old 05-10-2015
My first (un-)trap attempt:
Code:
trap 'exit 130' SIGINT

hth
# 4  
Old 05-10-2015
Hi Scrutinizer...

Excellent many thanks, worked a treat...

Test code for others to try:-
Code:
#!/bin/bash
function Ctrl_C() { echo " You can't do that... :oD"; }
trap Ctrl_C SIGINT
for n in {0..10}
do
	echo "You are in the for loop."
	sleep 1
done
trap - SIGINT
while true
do
	echo "Escape loop..."
	sleep 1
done

Results:-
Code:
Last login: Sun May 10 13:03:47 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> ./trap.sh
You are in the for loop.
You are in the for loop.
^C You can't do that... :oD
You are in the for loop.
^C You can't do that... :oD
You are in the for loop.
^C You can't do that... :oD
You are in the for loop.
^C You can't do that... :oD
You are in the for loop.
^C You can't do that... :oD
You are in the for loop.
^C You can't do that... :oD
You are in the for loop.
^C You can't do that... :oD
You are in the for loop.
^C You can't do that... :oD
You are in the for loop.
You are in the for loop.
Escape loop...
Escape loop...
Escape loop...
Escape loop...
^C
AMIGA:barrywalker~/Desktop/Code/Shell> _

Again many thanks...
This will be implemented in the next Scope upload...

EDIT:

Just realised bash has the 'help' command and it is in there! DOH!
Changed the line to 'trap - SIGINT'

Last edited by wisecracker; 05-10-2015 at 09:29 AM.. Reason: See above...
This User Gave Thanks to wisecracker For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automation of keyboard inputs..like Ctrl+d and Ctrl+a

Hi..! I'm stuck with my automation of starting a process and keeping it running even after the current ssh session has exited.. So i'm trying to use command 'screen'. which is doing exactly what i wanted, But the problem is automation of the same. i will have to press Ctrl+a and Ctrl+d for... (2 Replies)
Discussion started by: chandana hs
2 Replies

2. UNIX for Dummies Questions & Answers

Ctrl-V + Ctrl-J for newline character does not work inside vi editor

Hi friends, I am trying to add a newline char ('\n') between the query and the commit statement in the following shell script. #! /bin/sh echo "select * from tab; commit;" > data.sql I have tried typing in "Ctrl-V + Ctrl-J" combination which has inserted ^@ (NUL) character but the commit... (1 Reply)
Discussion started by: royalibrahim
1 Replies

3. Shell Programming and Scripting

How to handle CTRL+Z or CTRL+C in shells script?

Hi, while executing shell script, in the middle of the process, if we kill the shell script( ctrl+z or ctrl+c), script will be killed and the files which using for the script will be in the folder. How to handle those scenarios. Is there any possibilities, if user breaks the script, I need to... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

4. Shell Programming and Scripting

ctrl-c in script

how to send ctrl-c signal in scripts ??? i am executing top command in .exp script top command gives cpu running activities on your machine eg # top top - 18:41:01 up 8:38, 5 users, load average: 0.03, 0.16, 0.16 Tasks: 172 total, 1 running, 170 sleeping, 0 stopped, 1 zombie... (3 Replies)
Discussion started by: alexzander18
3 Replies

5. Shell Programming and Scripting

Ctrl-C or Ctrl-Z causing exit the session

H! I have written script where it need to invoke the perl script in background, then write the pid in temp file then bring back the job to foreground. whenever the Ctrl-C or Ctrl-Z is pressed in the script has to exit and prompt should be dispalyed. but this script causing exit from shell session... (2 Replies)
Discussion started by: jramesh1
2 Replies

6. Programming

Catch ctrl+d in C

Hello, I am programming some kind of shell in special distribution of Linux. My trouble comes with programming the sort function. It should work the same like in the standard shell. When you terminate input, there's need to put End Of Transmission character, which is CTRL+D. But I am not able to... (2 Replies)
Discussion started by: samciz
2 Replies

7. UNIX for Dummies Questions & Answers

CTRL/C does not work

Hi My CTRL/C does not work thought the STTY setting looks Ok Appreciate your assistance $stty -a speed 38400 baud; rows = 24; columns = 80; ypixels = 0; xpixels = 0; eucw 1:0:0:0, scrw 1:0:0:0 intr = ^c; quit = ^\; erase = ^?; kill = ^u; eof = ^d; eol = <undef>; eol2 = <undef>;... (10 Replies)
Discussion started by: zam
10 Replies

8. Shell Programming and Scripting

Catching ctrl-C or ctrl-D

Hi there, I'm using HP-UX 11 machine. I am running a script, thats gonna take a long time to execute. When I press ctrl-c to come out of my script, I have to catch that signal(ctrl-c) and display that ctrl-c had been pressed. How can I do it. Thanks in advance (2 Replies)
Discussion started by: sendhilmani123
2 Replies

9. AIX

Disable ctrl-c,ctrl-d,ctrl-d in ksh script

I wrote a ksh script for Helpdesk. I need to know how to disable ctrl-c,ctrl-z,ctrl-d..... so that helpdesk would not be able to get to system prompt :confused: (6 Replies)
Discussion started by: wtofu
6 Replies

10. UNIX for Dummies Questions & Answers

Script ctrl+c

How do you make a script so the user can not press ctrl+c and break out of the script? Thanks, :) (1 Reply)
Discussion started by: newtounix
1 Replies
Login or Register to Ask a Question