#!/bin/bash
# save as trap.sh
# catch exit signal
while true; do
 echo "test"
 trap 'echo "bye bye"; exit' 2
done

