开发者

running bash pipe commands in background with & ampersand

time for i i开发者_如何转开发n `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 ...


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


You can include the & in braces:

time for i in `ls /tmp/chunk*`; do
  {(cat $i | tr ' ' '\n' | sort | uniq > /tmp/line${i:10}) &};
done


& is a separator and so is redundant with ; I.E. remove the final ;

for i in /tmp/chunk*; do tr ' ' '\n' <$i | sort -u > /tmp/line${i:10}& done
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜