Skip to content

Instantly share code, notes, and snippets.

@seeker815
Created May 24, 2018 11:19
Show Gist options
  • Save seeker815/da62d8029b35c3b71aa1f66ff070a2c3 to your computer and use it in GitHub Desktop.
Save seeker815/da62d8029b35c3b71aa1f66ff070a2c3 to your computer and use it in GitHub Desktop.
trap with EXIT
#!/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