What signals does the trap command catch in the provided script?

QuestionsQuestions8 SkillsProBash Trap CommandNov, 29 2025
073

The trap command can catch various signals in a Bash script. Common signals that can be caught include:

  • SIGINT (2): Triggered by pressing Ctrl+C.
  • SIGTERM (15): Default termination signal.
  • SIGHUP (1): Sent when the terminal is closed.
  • SIGQUIT (3): Triggered by pressing Ctrl+.

You can specify which signals to catch in the trap command by listing them. For example:

trap 'echo "Caught SIGINT"' SIGINT

This command will execute the specified action when the SIGINT signal is received. You can catch multiple signals by separating them with spaces.

0 Comments

no data
Be the first to share your comment!