#!/bin/sh #An example trap script touch mytempfile # First set trap conditions for signals 0 and 1 trap "rm mytempfile ; echo Leaving my script " 0 trap " echo hang-up >>myerrorfile ; exit " 1 # Trap command on its own displays current trap settings trap # Display process ID so we can send it a signal from another window echo ID is $$ # If you send signal 1 during this next pause # The script will exit at the end of it. sleep 20 trap " " 2 echo " And now assume some commands " sleep 20 trap 2 echo " And some more commands " echo " And some more commands " sleep 20 exit