为什么是& ;"无效的语法? [英] Why is "& ;" invalid syntax?

查看:82
本文介绍了为什么是& ;"无效的语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在终端上运行一个for循环,在该终端上,我想将每个迭代发送到后台进程,以使它们全部同时运行.

I am trying to run a for loop on the terminal where I want to send each iteration to background process so that all of them run simultaneously.

以下是命令逐一运行

for i in *.sra; do fastq-dump --split-files $i ; done  # ";" only

我突出显示了分号.

要同时运行,这行得通

for i in *.sra; do fastq-dump --split-files $i & done  # "&" only

但这会导致错误

for i in *.sra; do fastq-dump --split-files $i & ; done  # "& ;"

如果有人解释这里发生的事情,那就太好了.我知道这应该以适当的缩进方式以Shell脚本的方式编写,但是有时候我只能运行此命令.

It would be nice if some one explains what is going on here. I know this should be written in a shell script way with proper indentation, but some times I only have this command to run.

推荐答案

&;都终止它们之前的命令.

& and ; both terminate the command that precedes them.

& ;的内容不能超过写; ;& &的内容,因为该语言只允许命令终止一次(并且不允许将零字列表作为命令) ).

You can't write & ; any more than you could write ; ; or & &, because the language only allows a command to be terminated once (and doesn't permit a zero-word list as a command).

因此:for i in *.src; do fastq-dump --split-files "$i" & done完全是正确的,不需要额外的;.

Thus: for i in *.src; do fastq-dump --split-files "$i" & done is perfectly correct as-is, and does not require an additional ;.

这篇关于为什么是& ;"无效的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆