我有shell脚本中的循环,它只需要处理列表中的几个文件的时间。 如何在后台推进进程,并在第一个文件仍在处理的同时select下一个文件?
for newfile in `ls new*` do time consuming process & done
我在/ dev / null 2>&1之后的命令末尾试了一下,但似乎没有成功。
把一个进程放在后台,只要把&放在最后去掉; 您曾经在done之前终止命令
for newfile in new* ; do long_running_command 2>&1 > /dev/null & done
你不需要这个
`ls new*`
你可以使用
new*
shell会为你扩展它。
例
touch new1 touch new2 for newfile in new* ; do ls $newfile 2>&1 > /dev/null & done
产生
[1] 92197 [1]+ Done ls $newfile 2>&1 > /dev/null [1] 92198 [1]+ Done ls $newfile 2>&1 > /dev/null