On Sun, Jul 14, 2024 at 8:40 PM Zachary Santer <zsan...@gmail.com> wrote:
>
> On Tue, Jul 9, 2024 at 2:37 PM Zachary Santer <zsan...@gmail.com> wrote:
> >
> > On the other hand, do funsubs give us the answer here?
> >
> > shopt -s lastpipe
> > declare -a pid=()
> > command-1 | tee >( command-2 ) ${ pid+=( "${!}" ); } >( command-3 ) ${
> > pid+=( "${!}" ); } >( command-4 ) ${ pid+=( "${!}" ); }
> > wait -- "${pid[@]}"
>
> This absolutely works, so there you go. When expanding multiple
> process substitutions as arguments to a command, you can save the $!
> resulting from each one by following it with an unquoted funsub that
> does that work and doesn't expand to anything.
>
> > That looks obnoxious
>
> I don't mind how it looks. It works.
>
> > declare -a pid=()
> > {
> >   commands
> > } {fd[0]}< <( command-1 )  ${ pid+=( "${!}" ); } {fd[1]}< <( command-2
> > ) ${ pid+=( "${!}" ); } {fd[2]}< <( command-3 ) ${ pid+=( "${!}" ); }
> >
> > Do things start breaking?
>
> Yeah, this doesn't work at all

Even that can be made to work by simply removing the space between the
process substitution and the following function substitution. Bash
treats the whole amalgamation as one word. See attached. That was run
by the current devel branch commit: c7439376a3.

Just noticed that, in the second set of procsubs, it looks like bash
is skipping over a potential pid from procsub to procsub. Not sure
what to make of that.

On Wed, Aug 7, 2024 at 12:03 PM Zachary Santer <zsan...@gmail.com> wrote:
>
> What's the purpose of 'wait' without id arguments
> being restricted to the final procsub, then? It sounds like the
> various issues revealed by Oğuz's October 2022 bug report were
> resolved by making other changes.

Backwards compatibility with people's expectations from earlier releases?

At least this is all documented.
zsant@Zack2021HPPavilion MSYS ~/repos/bash
$ ./bash ~/random/procsub-wait-solution true
+ : '5.3.0(1)-beta'
+ wait_explicit_pids=true
+ pid=()
+ declare -a pid
++ sleep 8
++ pid+=("${!}")
++ sleep 6
++ pid+=("${!}")
++ sleep 4
++ pid+=("${!}")
++ sleep 2
++ pid+=("${!}")
+ : /dev/fd/63 /dev/fd/62 /dev/fd/61 /dev/fd/60
+ SECONDS=0
+ : 'declare -a pid=([0]="6989" [1]="6990" [2]="6991" [3]="6992")' '$!=6992'
+ [[ true == true ]]
+ wait -- 6989 6990 6991 6992
+ : termination status 0 at 8 seconds
+ pid=()
+ printf 'The quick brown fox jumps over the lazy dog.\n'
++ sleep 8
++ pid+=("${!}")
++ sleep 6
++ pid+=("${!}")
++ sleep 4
++ pid+=("${!}")
++ sleep 2
++ pid+=("${!}")
+ tee -- /dev/fd/63 /dev/fd/62 /dev/fd/61 /dev/fd/60
The quick brown fox jumps over the lazy dog.
+ SECONDS=0
+ : 'declare -a pid=([0]="6994" [1]="6996" [2]="6998" [3]="7000")' '$!=7000'
+ [[ true == true ]]
+ wait -- 6994 6996 6998 7000
++ set +x
overly emphatic : The. Quick. Brown. Fox. Jumps. Over. The. Lazy. Dog.
++ set +x
shouting : THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
++ set +x
tortoise, actually : The quick brown fox jumps over the lazy tortoise.
++ set +x
line length : 44
+ : termination status 0 at 8 seconds
+ pid=()
+ fd=()
+ declare -a fd
++ sleep 8
++ pid+=("${!}")
++ sleep 6
++ pid+=("${!}")
++ sleep 4
++ pid+=("${!}")
++ sleep 2
++ pid+=("${!}")
+ :
+ SECONDS=0
+ : 'declare -a pid=([0]="7003" [1]="7004" [2]="7005" [3]="7006")' '$!=7006'
+ [[ true == true ]]
+ wait -- 7003 7004 7005 7006
+ : termination status 0 at 8 seconds

zsant@Zack2021HPPavilion MSYS ~/repos/bash
$ ./bash ~/random/procsub-wait-solution false
+ : '5.3.0(1)-beta'
+ wait_explicit_pids=false
+ pid=()
+ declare -a pid
++ sleep 8
++ pid+=("${!}")
++ sleep 6
++ pid+=("${!}")
++ sleep 4
++ pid+=("${!}")
++ sleep 2
++ pid+=("${!}")
+ : /dev/fd/63 /dev/fd/62 /dev/fd/61 /dev/fd/60
+ SECONDS=0
+ : 'declare -a pid=([0]="7008" [1]="7009" [2]="7010" [3]="7011")' '$!=7011'
+ [[ false == true ]]
+ wait
+ : termination status 0 at 2 seconds
+ pid=()
+ printf 'The quick brown fox jumps over the lazy dog.\n'
++ sleep 8
++ pid+=("${!}")
++ sleep 6
++ pid+=("${!}")
++ sleep 4
++ pid+=("${!}")
++ sleep 2
++ pid+=("${!}")
+ tee -- /dev/fd/63 /dev/fd/62 /dev/fd/61 /dev/fd/60
The quick brown fox jumps over the lazy dog.
+ SECONDS=0
+ : 'declare -a pid=([0]="7013" [1]="7015" [2]="7017" [3]="7019")' '$!=7019'
+ [[ false == true ]]
+ wait
++ set +x
overly emphatic : The. Quick. Brown. Fox. Jumps. Over. The. Lazy. Dog.
+ : termination status 0 at 2 seconds
+ pid=()
+ fd=()
+ declare -a fd
++ sleep 8
++ pid+=("${!}")
++ sleep 6
++ pid+=("${!}")
++ sleep 4
++ pid+=("${!}")
++ sleep 2
++ pid+=("${!}")
+ :
+ SECONDS=0
+ : 'declare -a pid=([0]="7022" [1]="7023" [2]="7024" [3]="7025")' '$!=7025'
+ [[ false == true ]]
+ wait
++ set +x
shouting : THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
+ : termination status 0 at 2 seconds

zsant@Zack2021HPPavilion MSYS ~/repos/bash
$ ++ set +x
tortoise, actually : The quick brown fox jumps over the lazy tortoise.
++ set +x
line length : 44

Attachment: procsub-wait-solution
Description: Binary data

Reply via email to