Date:        Mon, 24 Oct 2022 04:25:44 +0200
    From:        Emanuele Torre <torreemanue...@gmail.com>
    Message-ID:  
<CAA7hNqcb0mnoozhW_4rrutRcSuJzk6VQhe=50c7SxaAm9xM-=w...@mail.gmail.com>

  | bash performs an optimisation that runs redirections applied to simple
  | commands that run external programs, or subshell compound commands after
  | the fork(). (to avoid having to restore file descriptors after running
  | the command.)

It need not make a difference.   The wait command is not intended to
be just the wait(2) (or wait(3) whichever it is on the system in
question) system call (or wrapper around another system call).

There's no reason that wait (the command) cannot check for candidate
jobs which are still running, and wait for any of those, and then
return as soon as there are none left.   That the shell happens to
have forked other processes for its own reasons should make no
difference at all.

  | This causes other weird pitfalls, e.g. the following script loops
  | infinitely, and always runs `sleep 1 > /tmp/file1':
  |
  |     i=0
  |     while [ "$i" -lt 10 ]
  |         do sleep 1 > "/tmp/file$(( ++i ))"
  |     done

That is an entirely different issue, and is working as is supposed
to work.   That it isn't what some people might expect is irrelevant.

kre



Reply via email to