On Sun, Aug 23, 2026 at 11:47 AM <y.marchiani@netcourrier.com> wrote:
>
> Hello Mister Santer
>
> (I do assume it's Mister with your first name, sorry if I am wrong)
You're right.
> For clarity I will explain how I did write my code because I have multiples
> files (I did "follow" C language practice of dividing code in multiples files)
I'll admit I've written a couple of bash scripts that are more than a
thousand sloc each, all in one file. To each their own, I guess.
> I am using the <wait -p finished_pid -n "${list_of_pid[#]}"> command.
> If I am not wrong the -n option should only wait on one background job before
> continuing ; and the -p option means that the command will store the PID of
> the finished background job.
> I did think that those two options combined would remove only ONE PID at a
> time
Yep, that's what they should do.
I'm not going to dig through all that right now, but long story short,
try doing 'set -o posix' as the first thing that runs in your script.
We had a discussion about this[1], for like ... months. Chet Ramey,
the bash maintainer, ultimately made some real improvements, but some
of those are only enabled in POSIX mode. You could also try just not
calling the 'jobs' command.
> And if I have the values of the 4 variables set to "duration=10" the script
> return that the testing failed (if I look into the debugging files the wait
> command remove more than one job at a time)
> Is it normal behavior ??? I thought the -n and -p options together would only
> remove ONE PID at a time from the "jobs table".
At least in certain situations, 'wait -n' won't wait for or report the
termination status of processes that have already terminated when the
wait command is called. (Yes, along the same lines as what our South
Park character was saying, actually.) In particular, if job control or
the 'jobs' command has already notified the user of a process's
termination, 'wait -n' without pid arguments will ignore that process.
I *think* POSIX mode would resolve that in bash 5.3.
> Also yes I am using the "set -Eeuo pipefail" command but with the duration
> modified (100 ; 200 ; 300 ; 400) the script does work even with the "set -e"
> command... So I do assume it should no be a problem but I could be wrong...
It's just not great practice in general.[2] There's a lot of good
information on the Wooledge Wiki, so spend some time there.
[1] https://lists.gnu.org/archive/html/bug-bash/2024-07/msg00134.html
[2] https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail