[kanchilug] 1D1C - trap

  • From: Dhanasekar <tkdhanasekar@xxxxxxxxx>
  • To: ilugc@xxxxxxxxxxxxx, kanchilug@xxxxxxxxxxxxx, ilugd@xxxxxxxxxxxxxxxxxxxx
  • Date: Mon, 10 Apr 2023 06:00:00 +0530

trap - is used to execute a command when the shell receives any signal is
called `trap`.

syntax
$ trap [options] "[arguments]" [signals]

To display the list of all commands associated with each condition
$ trap

To display the list of all signal names with number
$ trap -l

To Set `trap` command with signal number of SIGUP, SIGQUIT and SIGKILL
$ trap 'echo Trap command executed' 1 3 9
$ press Ctrl+C
$ ^CTrap command executed
$ trap

To Set trap command for ERR and EXIT
$ trap 'rm file.txt' err exit
$ trap



regards,
T.Dhanasekar

Other related posts:

  • » [kanchilug] 1D1C - trap - Dhanasekar