Peng Yu
2018-02-12 17:36:50 UTC
Hi,
The trap in the coproc can be triggered. But when I type ctrl-c to
terminate the current program. It will not be triggered. Is there a
way to let the coproc get signals from the main program? Thanks
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
trap 'echo main' EXIT
coproc {
seq 3
trap 'echo mycoproc' EXIT
}
exec 3>&"${COPROC[0]}"
sleep 1
while IFS=$'\t' read -r -u 3 line
do
printf '%s\n' "$line"
done
$ ./main.sh
1
2
3
mycoproc
$ ./main.sh
^Cmain
The trap in the coproc can be triggered. But when I type ctrl-c to
terminate the current program. It will not be triggered. Is there a
way to let the coproc get signals from the main program? Thanks
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
trap 'echo main' EXIT
coproc {
seq 3
trap 'echo mycoproc' EXIT
}
exec 3>&"${COPROC[0]}"
sleep 1
while IFS=$'\t' read -r -u 3 line
do
printf '%s\n' "$line"
done
$ ./main.sh
1
2
3
mycoproc
$ ./main.sh
^Cmain
--
Regards,
Peng
Regards,
Peng