为什么“& ;"在bash中无效的语法? [英] Why is "& ;" invalid syntax in bash?
问题描述
以下是一个一个运行的命令
* .sra;做fastq-dump --split-files $ i;完成#;只有
我已经突出了分号。
要同时运行这个工程
for i in * .sra;做fastq-dump --split-files $ i&完成#&只有
但是这个错误
for i in * .sra;做fastq-dump --split-files $ i& ;完成#&;
如果有人解释这里发生了什么,那将会很好。我知道这应该写在一个合适的缩进shell脚本的方式,但有些时候,我只有这个命令来运行。
谢谢
&
和;
命令。
不能写& ;
不止可以写; ;
或& &
,因为语言只允许命令终止一次(并且不允许零字列表作为命令)。
< hr>
因此:用于i in * .src;做fastq-dump --split-files$ i&完成
完全正确,并且不需要额外的;
。
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.
Following is the command running one by one
for i in *.sra; do fastq-dump --split-files $i ; done # ";" only
I have highlighted the semicolon.
To run simultaneously this works
for i in *.sra; do fastq-dump --split-files $i & done # "&" only
but this gives an error
for i in *.sra; do fastq-dump --split-files $i & ; done # "& ;"
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.
Thanks
&
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).
Thus: for i in *.src; do fastq-dump --split-files "$i" & done
is perfectly correct as-is, and does not require an additional ;
.
这篇关于为什么“& ;"在bash中无效的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!