Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-24 Thread Chet Ramey
On 6/23/21 6:17 PM, Martin Jambon wrote: On 6/23/21 6:24 AM, Chet Ramey wrote: On 6/22/21 9:54 PM, Martin Jambon wrote: In the posix definition, a subshell - is not necessarily implemented as a separate process - belongs to a unique shell - is not a shell Why is it not "a shell?" Because

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-23 Thread Greg Wooledge
On Wed, Jun 23, 2021 at 03:17:48PM -0700, Martin Jambon wrote: > > What is the magic quality that imparts shellness? > > '$$' matching the process ID. That just signifies that you're in the original shell, or the main shell, or the root shell, or the fundamental shell, or make up whatever term

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-23 Thread Martin Jambon
On 6/23/21 6:24 AM, Chet Ramey wrote: On 6/22/21 9:54 PM, Martin Jambon wrote: In the posix definition, a subshell - is not necessarily implemented as a separate process - belongs to a unique shell - is not a shell Why is it not "a shell?" Because '$$' doesn't match its process ID. What

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-23 Thread Chet Ramey
On 6/22/21 9:54 PM, Martin Jambon wrote: In the posix definition, a subshell - is not necessarily implemented as a separate process - belongs to a unique shell - is not a shell Why is it not "a shell?" What is the magic quality that imparts shellness? -- ``The lyf so short, the craft so long

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-23 Thread Chet Ramey
On 6/22/21 8:00 PM, Lawrence Velázquez wrote: On Tue, Jun 22, 2021, at 6:32 PM, Martin Jambon wrote: I would also mention pipelines here, since these are more commonly used than () subshells. I don't know if there are other ways of creating subshells. If that's all, I think it would be

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Greg Wooledge
On Tue, Jun 22, 2021 at 06:54:18PM -0700, Martin Jambon wrote: > This is confirmed by this definition from posix: > > A subshell environment shall be created as a duplicate of the shell > environment, except [...] > In the posix definition, a subshell > - is not necessarily implemented as a

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Martin Jambon
On 6/22/21 6:11 PM, Lawrence Velázquez wrote: On Tue, Jun 22, 2021, at 8:52 PM, Martin Jambon wrote: It's better. However, the reader is still left wondering what "the shell" is referring to in first sentence. Subshells aside, I have a hard time believing that "the process ID of the shell"

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Dale R. Worley
> It's not the brace command; it's the pipeline. > >> Minimal repro: >> >>$ sleep 1 & { wait $!; } | cat >>[1] 665454 >>bash: wait: pid 665454 is not a child of this shell Interestingly, this is almost trivial to clairfy: $ sleep 5 & { wait $!; } [1] 19069 [1]+ Done

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Lawrence Velázquez
On Tue, Jun 22, 2021, at 8:52 PM, Martin Jambon wrote: > It's better. However, the reader is still left wondering what "the > shell" is referring to in first sentence. Subshells aside, I have a hard time believing that "the process ID of the shell" confuses anybody in practice. Even POSIX

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Martin Jambon
On 6/22/21 5:00 PM, Lawrence Velázquez wrote: Maybe something like this would get the point across: ($$) Expands to the process ID of the shell. In a subshell, it expands to the value that $$ has in the invoking shell. It's better. However, the reader is still left

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Lawrence Velázquez
On Tue, Jun 22, 2021, at 6:32 PM, Martin Jambon wrote: > I would also mention pipelines here, since these are more commonly > used than () subshells. I don't know if there are other ways of > creating subshells. If that's all, I think it would be valuable > to mention those two cases rather than

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Martin Jambon
On 6/22/21 1:37 PM, Greg Wooledge wrote: On Tue, Jun 22, 2021 at 01:12:10PM -0700, Martin Jambon wrote: On 6/22/21 4:31 AM, Greg Wooledge wrote: A pipeline creates two or more subshells, one for each command in the pipeline. Therefore, your wait command is running in a different process than

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Greg Wooledge
On Tue, Jun 22, 2021 at 01:12:10PM -0700, Martin Jambon wrote: > On 6/22/21 4:31 AM, Greg Wooledge wrote: > > A pipeline creates two or more subshells, one for each command in the > > pipeline. Therefore, your wait command is running in a different > > process than the one which created the sleep

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Martin Jambon
On 6/22/21 4:31 AM, Greg Wooledge wrote: On Tue, Jun 22, 2021 at 02:42:40AM -0700, Martin Jambon wrote: I ran into something that looks like a bug to me, although I'm not super familiar curly-brace command groups. Bash version: latest from GitHub mirror (commit ce23728: Bash-5.1 patch 7)

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Martin Jambon
On 6/22/21 6:15 AM, Chet Ramey wrote: On 6/22/21 5:42 AM, Martin Jambon wrote: Hello! I ran into something that looks like a bug to me, although I'm not super familiar curly-brace command groups. It's not the brace command; it's the pipeline. Thank you! It's the $$ that confused me since

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Chet Ramey
On 6/22/21 5:42 AM, Martin Jambon wrote: Hello! I ran into something that looks like a bug to me, although I'm not super familiar curly-brace command groups. It's not the brace command; it's the pipeline. Minimal repro:   $ sleep 1 & { wait $!; } | cat   [1] 665454   bash: wait: pid

Re: 'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Greg Wooledge
On Tue, Jun 22, 2021 at 02:42:40AM -0700, Martin Jambon wrote: > I ran into something that looks like a bug to me, although I'm not super > familiar curly-brace command groups. > > Bash version: latest from GitHub mirror (commit ce23728: Bash-5.1 patch 7) > > Minimal repro: > > $ sleep 1 & {

'wait' in command group in pipeline fails to recognize child process

2021-06-22 Thread Martin Jambon
Hello! I ran into something that looks like a bug to me, although I'm not super familiar curly-brace command groups. Bash version: latest from GitHub mirror (commit ce23728: Bash-5.1 patch 7) Minimal repro: $ sleep 1 & { wait $!; } | cat [1] 665454 bash: wait: pid 665454 is not a