-
Notifications
You must be signed in to change notification settings - Fork 37
/
24-trap.sh
20 lines (15 loc) · 681 Bytes
/
24-trap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
echo "
#############################################
## Example 24.1: #
## trap signals that run on EXIT and Ctrl+C #
#############################################
"
trap "echo we\'re exiting the script!" EXIT
trap "echo you pressed Ctrl+C" INT
echo 'press Ctrl+C here to see the INT signal handler run.'
# notice that Ctrl+C doesn't actually make the script exit, like it usually
# would! This is because trap replaces the normal signal handler for Ctrl+C
# (which would cause the script to exit). If you put an `; exit` at the end of
# the signal handler command, it'll exit the script
# this `read` just gives an opportunity to press Ctrl+C
read