I've "inherited" some shell scripts for Linux machines running the GNU "bash" shell. In one particular case, the machine runs GNU bash version 2.0.5b
One of those scripts has a wait &
("wait ampersand") instruction as part of the "for line" of a for
loop. At first sight, that seems to be a curious/interesting idiom, but my web searches for it did not return anything relevant. man wait
shows the "BASH_BUILTINS" ("BASH BUILTINS COMMAND") manpage, which has the following description:
wait [n]
Wait for the specified process and return its termination status.
n may be a process ID or a job specification; if a job spec is given,
all processes in that job's pipeline are waited for. If n is not
given, all currently active child processes are waited for, and the
return status is zero. If n specifies a non-existent process or job,
the return status is 127. Otherwise, the return status is the exit
status of the last process or job waited for.
By reading that part of this manpage, it seems to me that wait &
is silently (in the background) making sure that "all currently active child processes are waited for, and the return status is zero.". Am I right in this interpretation? Is this a common and/or useful idiom?
For added context, I'm talking about the following kind of usage in the script:
for file in `ls *.txt ; wait &`
do
...
[cp instructions]
...
[mv instructions]
...
[mailx instruction]
done