Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util (ble/builtin/trap): fix the EXIT trap in subshells
- Loading branch information
1 parent
480b7b3
commit 5b351e8
Showing
6 changed files
with
315 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
# function set_trap { for sig in INT QUIT; do trap "echo $sig >/dev/tty; trap - $sig; kill -$sig $BASHPID" "$sig"; done; } | ||
# function process_something { echo do >/dev/tty; for ((i=0;i<1000000;i++)); do :; done; echo done >/dev/tty; } | ||
|
||
function set_trap { | ||
trap 'echo INT >/dev/tty;trap - INT;kill -INT $BASHPID' INT | ||
} | ||
function process_something { | ||
echo start >/dev/tty | ||
for ((i=0;i<1000000;i++)); do :; done | ||
echo end >/dev/tty | ||
} | ||
|
||
case $1 in | ||
(direct) | ||
set_trap; process_something ;; | ||
(subshell) | ||
(set_trap; process_something) ;; | ||
(comsub) | ||
: $(set_trap; process_something) ;; | ||
(subshell-inherit) | ||
set_trap; (process_something) ;; | ||
(comsub-inherit) | ||
set_trap; : $(process_something) ;; | ||
(comsub-plain) | ||
: $(process_something) ;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.