shell


confirmed exit using trap


I am trying to trap the Ctrl+C signal asking a confirmation from the user. The trapping part works fine. But once the signal gets trapped and the user presses NO, it does not return to the normal execution. Instead, it quits the script. How to make it resume execution when the user presses no?
Here is my code:
hell()
{
echo "Do you want to quit? Press 1 for yes and 0 for no";
read n;
if [ $n == 1 ]; then
exit 1;
fi
}
trap "hell" SIGINT
find /
The problem here is the INT signal is being received by your script AND by your command find /, so it exits.
You can fully ignore the signal(s) with:
trap '' SIGNINT
I don't know if it's possible to catch the signal and prevent that your commands receive it.

Related Links

Input a command result in a command line program
How can I execute a script that runs within an xterm/xgterm?
ssh executing nsenter as remote command with interactive shell in golang to debug docker container
ksh88 changing single quotes to double quotes inside heredocs?
Shell script replace variable with another variable have content & character by using sed
shell script that send email before exiting
how can we remove last 7 lines of file in unix [duplicate]
Shell Script improvement for getting diff result
hbase shell command - scan and Filter
How can I conditionalize a WiX custom action based on user priviledges
What does 1>&2 mean in shell? [duplicate]
UNIX: recursively paste a substring into the same string in unix
docker login in shell script dont work
Run a script every x seconds without waiting for it to complete
rename files in current folder (mandatory : for mv cut commands)
How to feed the output of one pipe to another pipe?

Categories

HOME
algorithm
django
oracle12c
facebook-oauth
battery
apiblueprint
bitbucket-api
pyqt4
barcode
computer-science
teechart
extjs4.2
32bit-64bit
pcl-crypto
enthought
heap
activecollab
3nf
linear-algebra
dynamic-sql
bourbon
asp.net-core-webapi
jasmine-node
outliers
nstimer
firebase-analytics
wcag
rpgle
twiml
cart
hibernate-validator
hard-drive
modalviewcontroller
baidu-map
batching
navigator
openproject
ideascript
azure-arm
doc
datacachefactory
chronicle-map
outputcache
contract
getchar
textsum
clarifai
cnc
dtsearch
insight
colorbar
cd-burning
materialized-path-pattern
webjars
mta
jodd
i386
ng-grid
dimension
observablecollection
kango-framework
riot
data-protection
invoke-sqlcmd
realsense
mobiledoc-kit
jaunt-api
concept-insights
maybe
poppler
toolkit
visual-sourcesafe-2005
jdk1.7
amiga
openbabel
delayed-execution
iiop
contrast
formview
machine-instruction
extjs2
openargs
scrypt
time.h
facebook-timeline
fb.ui
android-loadermanager
qi4j
midlet
monotouch.dialog
oracle-enterprise-linux
usertype
box2d-iphone
android-holo-everywhere
tmx
socketserver
mtu
tabpanel
lxr
build-environment
interop-domino
asynchronous-wcf-call
sifr3
fail-fast-fail-early
perl5.12

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App