{
	"id": "7b5e5f03-e2d5-4076-bb23-bebe0adfdb6f",
	"created_at": "2026-04-06T00:08:14.212019Z",
	"updated_at": "2026-04-10T03:21:03.20366Z",
	"deleted_at": null,
	"sha1_hash": "67d3a6bedaa6cc8a6c7b3aa41b4f25cc55d36c6f",
	"title": "trap Man Page - Linux",
	"llm_title": "",
	"authors": "",
	"file_creation_date": "0001-01-01T00:00:00Z",
	"file_modification_date": "0001-01-01T00:00:00Z",
	"file_size": 59770,
	"plain_text": "trap Man Page - Linux\r\nArchived: 2026-04-05 23:01:58 UTC\r\nSS64\r\nLinux\r\nHow-to\r\nExecute a command when the shell receives a signal.\r\nSyntax\r\n trap [-lp] [[arg] sigspec ...]\r\nKey\r\n -p Display signal commands (or trap commands for sigspec)\r\n -l Print a list of signal names and their corresponding numbers.\r\n arg The command to be executed when the shell receives signal(s) sigspec.\r\nIf arg is absent (and there is a single sigspec) or -, each specified signal is reset to its original disposition (the\r\nvalue it had upon entrance to the shell).\r\nIf arg is the null string the signal specified by each sigspec is ignored by the shell and by the commands it\r\ninvokes.\r\nIf arg is not present and -p has been supplied, then the trap commands associated with each sigspec are displayed.\r\nIf no arguments are supplied or if only -p is given, trap prints the list of commands associated with each signal.\r\nEach sigspec is either a signal name, or a signal number. Signal names are case insensitive and the SIG prefix is\r\noptional.\r\nNumber SIG Meaning\r\n0 0 On exit from shell\r\n1 SIGHUP Clean tidyup\r\n2 SIGINT Interrupt (CTRL-C)\r\n3 SIGQUIT Quit\r\n6 SIGABRT Cancel\r\n9 SIGKILL Die Now (cannot be trap'ped)\r\n14 SIGALRM Alarm Clock\r\n15 SIGTERM Terminate\r\nhttps://ss64.com/bash/trap.html\r\nPage 1 of 3\n\nIf a sigspec is EXIT (0) the command arg is executed on exit from the shell.\r\nIf a sigspec is DEBUG, the command arg is executed before every simple command, for command, case\r\ncommand, select command, every arithmetic for command, and before the first command executes in a shell\r\nfunction (see SHELL GRAMMAR). Refer to the description of the extdebug option to the shopt builtin for details\r\nof its effect on the DEBUG trap.\r\nIf a sigspec is ERR, the command arg is executed whenever a simple command has a non-zero exit status, subject\r\nto the following conditions. The ERR trap is not executed if the failed command is part of the command list\r\nimmediately following a while or until keyword, part of the test in an if statement, part of a \u0026\u0026 or || list, or if the\r\ncommand’s return value is being inverted via !.\r\nThese are the same conditions obeyed by the errexit option.\r\nIf a sigspec is RETURN, the command arg is executed each time a shell function or a script executed with the . or\r\nsource builtins finishes executing.\r\nSignals ignored upon entry to the shell cannot be trapped or reset.\r\nTrapped signals that are not being ignored are reset to their original values in a child process when it is created.\r\nWhen Bash receives a signal for which a trap has been set while waiting for a command to complete, the trap will\r\nnot be executed until the command completes. When Bash is waiting for an asynchronous command via the wait\r\nbuilt-in, the reception of a signal for which a trap has been set will cause the wait built-in to return immediately\r\nwith an exit status greater than 128, immediately after which the trap is executed.\r\nThe return status is False if any sigspec is invalid; otherwise trap returns True.\r\nThis is a BASH shell builtin, to display your local syntax from the bash prompt type: help trap\r\nExamples\r\n#!/bin/bash\r\n$ SCRATCH=$(mktemp -t tmp.XXXXXXXXXX)\r\ntrap cleanup 1 2 3 6\r\ncleanup()\r\n{\r\n echo \"Cleaning up temp files:\"\r\n rm -rf \"$SCRATCH\"\r\n exit 1\r\n}\r\n### continue main script below\r\n“When elephant steps on a trap, no more trap” ~ African Proverb\r\nhttps://ss64.com/bash/trap.html\r\nPage 2 of 3\n\nRelated Linux commands\r\nexec - Execute a command.\r\nCopyright © 1999-2026 SS64.com\r\nSome rights reserved\r\nSource: https://ss64.com/bash/trap.html\r\nhttps://ss64.com/bash/trap.html\r\nPage 3 of 3",
	"extraction_quality": 1,
	"language": "EN",
	"sources": [
		"MITRE"
	],
	"references": [
		"https://ss64.com/bash/trap.html"
	],
	"report_names": [
		"trap.html"
	],
	"threat_actors": [],
	"ts_created_at": 1775434094,
	"ts_updated_at": 1775791263,
	"ts_creation_date": 0,
	"ts_modification_date": 0,
	"files": {
		"pdf": "https://archive.orkl.eu/67d3a6bedaa6cc8a6c7b3aa41b4f25cc55d36c6f.pdf",
		"text": "https://archive.orkl.eu/67d3a6bedaa6cc8a6c7b3aa41b4f25cc55d36c6f.txt",
		"img": "https://archive.orkl.eu/67d3a6bedaa6cc8a6c7b3aa41b4f25cc55d36c6f.jpg"
	}
}