BASH 语句单独执行但返回“no such file”在 for 循环中
又一个我找不到答案,感觉我已经疯了。
我有一个 BASH 脚本,使用 for 循环在很多文件(~5000)上运行复杂的命令(许多蛋白质序列比对)。循环生成的语句将在单独给出时执行(即从错误消息复制粘贴到命令提示符),但在循环内返回“没有这样的文件或目录”。下面的脚本;实际上还有几个参数,但这包括一些代表性的参数和文件参数。 <代码>
#!/bin/bash
# 将目标目录作为 FASTA 序列作为参数传递。
# psiblast 的参数
# 常见的
db=本地/db/nr/nr
outfile="/mnt/scratch/psi-blast"
e=0.001
线程=8
itnum=5
pssm="/mnt/scratch/psi-blast/pssm。"
pssm_txt="/mnt/scratch/psi-blast/pssm。"
伪=0
pwa_inclusion=0.002
对于 ${1}/* 中的 i
做
文件名=$(基本名$i)
“本地/ncbi-blast-2.2.23+/bin/psiblast\
-查询${i}\
-db $db\
-out ${outfile}/${文件名}.out\
-评估$e\
-num_threads $线程\
-num_iterations $itnum\
-out_pssm ${pssm}$文件名\
-out_ascii_pssm ${pssm_txt}${文件名}.txt\
-伪计数$伪\
-inclusion_ethresh $pwa_inclusion"
完毕
运行此脚本会给出“
每个命令都需要几分钟才能运行。
Another one I can't find an answer for, and it feels like I've gone mad.
I have a BASH script using a for loop to run a complex command (many protein sequence alignments) on a lot of files (~5000). The loop produces statements that will execute when given alone (i.e. copy-pasted from the error message to the command prompt), but which return "no such file or directory" inside the loop. Script below; there are actually several more arguments but this includes some representative ones and the file arguments.
#!/bin/bash# Pass directory with targets as FASTA sequences as argument. # Arguments to psiblast # Common db=local/db/nr/nr outfile="/mnt/scratch/psi-blast" e=0.001 threads=8 itnum=5 pssm="/mnt/scratch/psi-blast/pssm." pssm_txt="/mnt/scratch/psi-blast/pssm." pseudo=0 pwa_inclusion=0.002
for i in ${1}/* do filename=$(basename $i) "local/ncbi-blast-2.2.23+/bin/psiblast\ -query ${i}\ -db $db\ -out ${outfile}/${filename}.out\ -evalue $e\ -num_threads $threads\ -num_iterations $itnum\ -out_pssm ${pssm}$filename\ -out_ascii_pssm ${pssm_txt}${filename}.txt\ -pseudocount $pseudo\ -inclusion_ethresh $pwa_inclusion" done
Running this scripts gives "<scriptname> line <last line before 'done'>: <attempted command> : No such file or directory. If I then paste the attempted command onto the prompt it will run.
Each of these commands takes a couple of minutes to run.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试不带引号。你忘记了一些斜杠。
try without the quotes. and you forgot some slashes.
如果您正在迭代的文件名中有空格,就会发生您所观察到的行为。因此,您需要正确引用文件名,如以下最小示例所示:
The behavior you're observing will occur if there are spaces in the filenames you're iterating over. For this reason, you'll want to properly quote your filenames, as in the following minimal example:
使用 for 循环时,向文件名添加引号不会有帮助。为了克服这个问题,每当我需要循环文件名时,我总是执行类似于以下示例的操作:
Adding quotes to filenames will not help when using a for loop. To overcome this, I've always done something similar to the following example whenever I needed to loop over filenames: