Sample Header Ad - 728x90

How does bash know about its parent's coprocess in this situation, and why does a shebang line change it?

2 votes
1 answer
6338 views
outer.sh:
ls -l /proc/$$/exe
coproc cat
./inner.sh
kill $!
inner.sh:
ls -l /proc/$$/exe
set | grep COPROC || echo No match found
coproc cat
kill $!
When I run ./outer.sh, this gets printed:
lrwxrwxrwx 1 joe joe 0 Jun 16 22:47 /proc/147876/exe -> /bin/bash
lrwxrwxrwx 1 joe joe 0 Jun 16 22:47 /proc/147879/exe -> /bin/bash
No match found
./inner.sh: line 3: warning: execute_coproc: coproc [147878:COPROC] still exists
Since COPROC and COPROC_PID aren't set in the child, how does it know about the one from the parent to be able to give me that warning? Also, I discovered that if I add #!/bin/bash to the top of inner.sh, or if I call bash ./inner.sh instead of just ./inner.sh from outer.sh, then the warning goes away. Why does this change anything, since it's getting ran with a bash subprocess either way?
Asked by Joseph Sible-Reinstate Monica (4220 rep)
Jun 17, 2022, 02:49 AM
Last activity: Jun 17, 2022, 07:33 AM