#!/bin/sh # Translate argument list to individual function calls with one argument. trap_with_arg() { func="$1" shift for sig; do trap "$func $sig" "$sig" done } # register signal handlers with the custom trap_with_arg function. # translates to: # trap _trap HUP # trap _trap INT # ... trap_with_arg _trap HUP INT WINCH QUIT TERM INFO USR1 USR2 # the trap function get's the signal as argument now _trap() { echo "Caught signal: $1" case $1 in INT) exit 1 ;; QUIT) exit 0 ;; WINCH) echo "Resize: $(tput cols)x$(tput lines)" ;; esac } # main program... just waiting. while true do sleep 0.1 done