Created
March 17, 2012 14:46
-
-
Save CrBoy/2060346 to your computer and use it in GitHub Desktop.
The `trap' in bash scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
trap "echo TRAP!!; exit" SIGTERM SIGINT SIGHUP | |
for (( i=0; i<5; i=i+1 )) | |
do | |
echo $i | |
sleep 1 | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function clean_up { | |
echo CLEAN UP!! | |
exit | |
} | |
trap clean_up SIGTERM SIGINT SIGHUP | |
for (( i=0; i<5; i=i+1 )) | |
do | |
echo $i | |
sleep 1 | |
done | |
clean_up |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function clean_up { | |
echo CLEAN UP!! | |
} | |
trap "clean_up;exit" SIGTERM SIGINT SIGHUP | |
for (( i=0; i<5; i=i+1 )) | |
do | |
echo $i | |
sleep 1 | |
done | |
clean_up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment