Created
May 24, 2018 11:19
-
-
Save seeker815/da62d8029b35c3b71aa1f66ff070a2c3 to your computer and use it in GitHub Desktop.
trap with EXIT
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 | |
# trap1 | |
trap suicide EXIT SIGINT SIGQUIT | |
suicide (){ | |
if [ $? -ne 0 ]; then | |
echo "You hit Cntrl+c, exiting" | |
fi | |
exit | |
} | |
count=0 | |
for ((i=1;i<=500;i++)); | |
do | |
# your-unix-command-here | |
echo $i | |
sleep 1 | |
datei | tee /tmp/test1.log | |
if [ "${PIPESTATUS[0]}" != 0 ]; then | |
suicide | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment