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

Format data using Awk Statemnt
Passing environment variables over ssh for remote expansion
Providing input for additional authentication using Plink
Way to create multiline comments in Bash?
How do you execute a SHELL script in multiple directories without having to generate a run script
How to stop GNU make from expanding dollar signs in MAKEFILE_LIST?
POSIX shell: escaping line-continuations in backquote command-substitutions
ms-dos command shell sort returns “Input file specified two times.”
Shell script: Want to find all files in last hour and cat the last 1000 lines to 1 log file
Need to a grep a file for specific word and count the occurrence for every hour
MSAccess VBA Shell Command - Max Length?
How to compute spectrum using awk or shell scripting?
Shell command to count lines in a file
gitlab ci false passed
How compute trend using awk?
Chrome shell script

Categories

HOME
google-app-engine
google-cloud-platform
design-patterns
deep-learning
time-complexity
apache-flink
sh
entity-framework-core
switch-statement
dojo
cakephp-3.4
tail
jquery-ui
computer-science
qpython
distribution
mod-security
java.util.logging
selenium-ide
symbol
http-post
dimensional-modeling
solrcloud
string-concatenation
flask-sqlalchemy
highstock
ckfinder
stackexchange
bulletphysics
fragment-backstack
oculus
linked-data
tizen-tv
ntp
scatter3d
postback
zend-debugger
paragraph
cognos-bi
database-comparison
catch-unit-test
android-sugarorm
contacts
getpixel
carriage-return
modalviewcontroller
jwplayer6
least-squares
salesforce-communities
playframework-2.1
postgresql-8.4
wmp
oracle-service-bus
memory-mapping
gitlist
rserve
git-flow
rackspace-cloud
flac
cpu-cache
stax
file-uri
nikeplus-api
swizzling
mediametadataretriever
false-sharing
rasterize
asyncdisplaykit
grgit
roadkill-wiki
rubaxa-sortable
sapscript
canalyzer
dronekit-android
jsvc
airbrake
botan
bcache
grouping-sets
dbaccess
mruby
formview
device-tree
ss7
mintty
reflector
http-patch
scrypt
mbunit
ice-cube
rolify
process-explorer
wp7test
subgraph
josql
ilasm
google-maps-mobile
agility.js
flex-mobile
expression-blend-4
w3c-geolocation
undefined-index
binomial-heap
sifr3
linfu-dynamicproxy
ifilter

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