Including bash / sh in unexpected behavior, and I wonder if someone can explain the rationale for this question and give a solution to the question below.
In an interactive bash shell session, I do:
$ bash -c 'sleep 10 && echo'
With ps on Linux, it looks like this:
\_ -bash \_ bash -c sleep 10 && echo \_ sleep 10
The process tree is what I would expect:
- My bash shell interactive process (
$ ) - Shell process for children (
bash -c ... ) - sleeping baby process
However, if part of the command of my bash -c is a single command, for example:
$ bash -c 'sleep 10'
Then the middle sub-shell is swallowed, and my interactive terminal session is performing โdirectlyโ when the children process the process. The process tree is as follows:
\_ -bash \_ sleep 10
So, from the perspective of the process tree, these two results give the same result:
$ bash -c 'sleep 10'$ sleep 10
What's going on here?
Now to my question: is there a way to force an intermediate shell, regardless of the complexity of the expression passed to bash -c ... ?
(I could add something like ; echo; to my actual command and that "works", but I would prefer. Is there a better way to make the intermediate process exist?)
(edit: typo in ps output, remove the sh tag, as mentioned in the comments, another typo)
linux bash shell subshell
Marco
source share