Skip to content

Commit 173d9f1

Browse files
committed
Fix trap usage to correctly exit script
When a signal like `SIGINT` (Ctrl+C) is received, the shell **interrupts the current command** and runs the trap handler. After the trap completes, the shell **resumes execution** from where it was interrupted - unless the trap explicitly calls `exit`.
1 parent 1df7862 commit 173d9f1

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

esh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ export ESH="$0"
358358

359359
if [ "${OUTPUT#-}" ]; then
360360
tmpfile="$(mktemp)"
361-
trap 'rm -f -- "$tmpfile"' EXIT HUP INT TERM
361+
trap 'rm -f -- "$tmpfile"; exit 0' EXIT
362+
trap 'rm -f -- "$tmpfile"; exit 130' HUP INT TERM
362363
process "$INPUT" "$vars" "$EVALUATE" > "$tmpfile"
363364
cat "$tmpfile" > "$OUTPUT"
364365
else

0 commit comments

Comments
 (0)