Thursday, April 19, 2007

Trapping signals (^C and ^Z) in Bash

#!/bin/bash
#Script written by Vaibhav Gupta
#Trapping HUP TERM INT and ^Z in shell.

echo "Process ID = $$";
stty susp "" #Trapping CTRL-Z
trap 'echo "Trapping CTRL-C, TERM and HUP";' HUP TERM INT
echo

echo "Sleeping for some time"
for i in `seq 1 20`; do
    sleep 1
    echo -n "."
done
echo
stty susp "^Z"


No comments: