It's in the man page, of course, but who reads those, right? I'm betting the answer is bound to be found on some blog through Google in 0.76 seconds flat ;)
So it turns out it's fairly simple and this demonstrates it:"If arg is absent (and there is a single sigspec) or -, each specified signal is reset to its original disposition (the value it had upon entrance to the shell)."
root@mgmtsrv:~# cat test.sh
#!/bin/bash
trap 'echo TRAPPED!; break' SIGINT
while [ True ]; do
sleep 1
done
echo 'end of script'
exit 0
root@mgmtsrv:~# ./test.sh
^CTRAPPED!
end of script
root@mgmtsrv:~#
Now, let's unset the trap:root@mgmtsrv:~# cat test.sh
#!/bin/bash
trap 'echo TRAPPED!; break' SIGINT
while [ True ]; do
sleep 1
done
trap - SIGINT
while [ True ]; do
sleep 1
done
echo 'end of script'
exit 0
root@mgmtsrv:~# ./test.sh
^CTRAPPED!
^C
root@mgmtsrv:~#
So, in short: the 'trap - SIGINT' line clears the set trap :)
No comments:
Post a Comment