使用 & 符号在后台运行 bash 管道命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6666245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
running bash pipe commands in background with & ampersand
提问by Tathagata
time for i in `ls /tmp/chunk*`; do (cat $i | tr ' ' '\n' | sort | uniq > /tmp/line${i:10}) & ;done
bash: syntax error near unexpected token `;'
Whats the syntax error in the above command? I also tried using {}and ended the piped commands with ;. But same error shows up ...
上面命令中的语法错误是什么?我还尝试使用{}并以;. 但同样的错误出现...
回答by Fred Foo
You should put the &inside the (), if you want to run all the jobs in parallel in the background.
你应该把&里面的(),如果你要并行运行的所有作业的背景。
time for i in `ls /tmp/chunk*`; do
(cat $i | tr ' ' '\n' | sort | uniq > /tmp/line${i:10} &)
done
回答by IcanDivideBy0
You can include the & in bracers:
您可以在括号中包含 & :
time for i in `ls /tmp/chunk*`; do
{(cat $i | tr ' ' '\n' | sort | uniq > /tmp/line${i:10}) &};
done
回答by pixelbeat
& is a separator and so is redundant with ; I.E. remove the final ;
& 是一个分隔符,因此与 ; 是多余的 IE 删除最后;
for i in /tmp/chunk*; do tr ' ' '\n' <$i | sort -u > /tmp/line${i:10}& done

