Skip to content

Instantly share code, notes, and snippets.

@seeker815
Created May 24, 2018 11:09
Show Gist options
  • Save seeker815/2c3ebf3550f8aa651d6f86c346c4e88a to your computer and use it in GitHub Desktop.
Save seeker815/2c3ebf3550f8aa651d6f86c346c4e88a to your computer and use it in GitHub Desktop.
Pattern to trap signals to make your bash script robust
#!/bin/bash
# trap
trap suicide SIGINT SIGHUP SIGQUIT
suicide (){
echo $?
echo "You hit Cntrl+c, exiting"
exit
}
for ((i=1;i<=500;i++));
do
# your-unix-command-here
echo $i
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment