Skip to content

Instantly share code, notes, and snippets.

@kuntalchandra
Created August 23, 2017 11:51
Show Gist options
  • Save kuntalchandra/b9396b627920feacd9a28488c7fabbdc to your computer and use it in GitHub Desktop.
Save kuntalchandra/b9396b627920feacd9a28488c7fabbdc to your computer and use it in GitHub Desktop.
bash: Trap error and exit
#!/bin/bash
trap "exit 1" TERM
TOP_PID=$$
function alert()
{
echo "Do something"
kill -s TERM $TOP_PID
}
echo "Function call to stop execution"
alert
echo "This message won't be printed ever"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment