LPIC-1 Shells, Scripting and Data Management Practice Question
A system administrator runs a script that contains the line: trap 'echo "Cleaning up..."' EXIT. The script is executed and then receives SIGINT (Ctrl+C) before normal completion. What happens?
⚠ Common exam trap
The trap here is believing that an EXIT trap only fires on successful completion, when in fact it also runs when the shell is terminated by a signal.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The trap on EXIT is executed because SIGINT causes the shell to exit.
The EXIT trap runs when the shell exits, regardless of whether the exit is normal or caused by a signal that terminates the shell. When SIGINT is received and not otherwise trapped, the shell exits, triggering the EXIT trap before termination. This makes EXIT suitable for cleanup actions such as removing temporary files.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The trap on EXIT is ignored because the script was interrupted by a signal.
Why it's wrong here
The EXIT trap is specifically designed to run when the shell exits, including exits caused by receiving a signal that terminates the shell. It is not skipped merely because the exit was triggered by SIGINT. Assuming otherwise would defeat the purpose of using EXIT for cleanup.
- ✓
The trap on EXIT is executed because SIGINT causes the shell to exit.
Why this is correct
When a script receives SIGINT, the default action terminates the shell. Because the EXIT trap is set, the shell runs the trap command just before it exits, regardless of the reason for termination. The echo is therefore executed during the SIGINT-triggered exit, matching the described behavior.
- ✗
The trap on EXIT is executed only if the script completes normally.
Why it's wrong here
The EXIT trap is not limited to normal completion; it also runs when the shell exits due to a signal or an explicit exit command. That is precisely why it is commonly used for cleanup tasks. Restricting it to normal completion would make it unreliable for handling interruptions.
- ✗
The script continues running because SIGINT is trapped and ignored by default.
Why it's wrong here
SIGINT is not trapped by default; the shell's default action is to terminate upon receiving it. The presence of an EXIT trap does not change that default disposition for SIGINT. The script would not continue running unless a specific trap for SIGINT was set to ignore or handle it.
Go deeper
Related to this question
About these practice questions
This LPIC-1 question is part of Courseiva's 402-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official LPI exam blueprint
This LPIC-1 practice question is part of Courseiva's free LPI certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LPIC-1 exam.