#!/bin/bash
( sleep 10; echo foo; )
echo bar
- start to run the code
- during the sleep, send SIGINT (Ctrl+C)
- is there a chance of ever seeing “bar” on the output?
The reasoning being:
()
creates a subprocess, which processes the signal first, so the main bash process sees that the command has returned, and executes the next line of code before getting to process the SIGINT.
A variation:
#!/bin/bash
( sleep 10; echo foo; ) &
wait -f
echo bar
This is not something I have seen, or a possible bug, etc, I just want to know, how this is supposed to work?
I think, that the SIGINT is propagated from the parent process to the child, and thus the main bash process should be aware of the signal by the time the subprocess returns, so the echo bar
is never executed, but this is just what I expect, and maybe not what actually happens.
(bash version 5)