为什么“& ;"在bash中无效的语法? [英] Why is "& ;" invalid syntax in bash?

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

问题描述

我试图在终端上运行一个for循环,我想把每个迭代发送到后台进程,这样所有的循环都可以同时运行。



以下是一个一个运行的命令

  * .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 ;.

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

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