我已经“继承”了运行GNU“ bash” shell的Linux机器的一些shell脚本。在一种特定情况下,机器运行GNU bash版本2.0.5b
这些脚本之一有一个wait &
(“&”符号)作为for
循环“ for行”的一部分。乍一看,这似乎是一种好奇/有趣的习惯用法,但是我在网上搜索时并未返回任何相关信息。man wait
显示了“ BASH_BUILTINS”(“ BASH BUILTINS COMMAND”)联机帮助页,该联机帮助具有以下描述:
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.
通过阅读该手册页的那部分,在我看来,它wait &
是在默默地(在后台)确保“ 正在等待所有当前活动的子进程,并且返回状态为零 ”。我的解释正确吗?这是常见和/或有用的习语吗?
为了增加上下文,我正在谈论脚本中的以下用法:
for file in `ls *.txt ; wait &`
do
...
[cp instructions]
...
[mv instructions]
...
[mailx instruction]
done