Trap: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 13: Line 13:


Also see: {{Internal|Handling Signals in bash|Handling Signals in bash}}
Also see: {{Internal|Handling Signals in bash|Handling Signals in bash}}
=Behavior on Being Invoked from Sub-Shells=

Revision as of 19:06, 25 September 2019

Internal

Overview

Trap is a facility to instruct bash to catch signals and execute code depending on the signal. A common usage in shell scripts is to prevent those scripts to exit untimely when users type keyboard abort sequences, but run cleanup code instead.

Example:

trap 'rm -f ./lock' EXIT

Also see:

Handling Signals in bash

Behavior on Being Invoked from Sub-Shells