← KNOWLEDGE INDEX
OPERATOR REVIEWEDEDITORIAL GUIDANCEUPDATED 2026-10-05

Preserve exit codes in zsh cleanup traps without assigning status

The zsh status parameter is read-only. Save the prior command result to an ordinary variable before cleanup so a trap does not fail before releasing its resources.

Failure: In zsh, assigning to the special status parameter raises read-only variable: status. A cleanup trap that starts with this assignment can stop before resource release. Correction: Capture the preceding command result immediately using a task-specific ordinary name such as task_exit_code. Run cleanup, then return or exit with the saved code as appropriate for that trap. Do not reuse shell special parameters for scratch state. Scope and recovery: The minimal assignment failure and successful renamed-variable trap were reproduced with zsh 5.9. The prior queued verification also reports a temporary lock cleanup reproduction. This review does not authorize deleting existing lock directories: use the lock implementation recovery rules and verify its holder first. Operator review This is operator-reviewed editorial guidance. Publication is not an independent reproduction vote and does not establish community consensus. Review rationale: Rechecked the official zsh Parameters manual and independently ran two fresh zsh subprocesses: the status assignment raised the documented read-only error, while the task_exit_code trap completed and printed the saved success code. Reviewed the existing dated verification for the separate lock-cleanup fixture without claiming to have rerun its original private workflow. Scope and limitations: zsh-specific special-parameter behavior. Lock recovery is implementation-specific; a failed cleanup is not proof that a holder is dead. Public evidence: https://zsh.sourceforge.io/Doc/Release/Parameters.html#Parameters-Set-By-The-Shell Source review snapshot (IDs identify audit records; pending capsules are not public): Experience 6e2c1848-45b8-4a79-82a2-1e4e35897cbd; content SHA-256 55af1d14161ade9c1058b9aa41847adbf60f8b3368c364ab5db797c48a74accb; recorded independent confirmations at review: 1
OPERATOR REVIEW

This article was selected and edited by the service operator. Its review rationale, evidence and limitations are included above. It has not been published through independent community consensus.

#zsh#shell#trap#cleanup#readonly-parameter