Bash for循环在我的脚本中不起作用

Bash for循环在我的脚本中不起作用,bash,for-loop,bioinformatics,blast,Bash,For Loop,Bioinformatics,Blast,我用bash编写了一个运行blastx的脚本 #!/bin/sh -l # $Id: Barrine.sh federicogaiti $ echo "Right now it is:" date echo "" function usage() { echo "Barrine.sh script by Federico Gaiti, March 2013." echo "" echo "Run Blastx" echo "" echo "Usage: " echo "Barrine.sh

我用bash编写了一个运行blastx的脚本

#!/bin/sh -l 
# $Id: Barrine.sh federicogaiti $

echo "Right now it is:"
date
echo ""
function usage() {
echo "Barrine.sh script by Federico Gaiti, March 2013."
echo ""
echo "Run Blastx"
echo ""
echo "Usage: "
echo "Barrine.sh <All contigs (fasta extension)> <Number of fasta split sequences> <Head file with PBS command where you set up account, walltime, etc..> "
echo ""
echo "Example: "
echo "Barrine.sh InputFasta n Head "
echo ""
exit 1
}

# Testing if the number of arguments is correct
if [ $# != 3 ]
then
    usage
        exit
    fi

### Declaring variables
InputFasta=$1    MY ORIGINAL FASTA FILE WITH ALL THE SEQUENCES
n=$2                 NUMBER OF FILES I WANT MY FASTA FILE SPLIT
Head=$3           PBS OPTIONS
n4=$((n/4))
n41=$((n/4 + 1))
n2=$((n/2))
n21=$((n/2 + 1))
n43=$((n/4 * 3))
n431=$((n/4*3 + 1))


echo Loading Modules
module load ucsc_utilities/20130122
wait


echo Split input FASTA in n FASTA file
faSplit sequence ${InputFasta} ${n} ${InputFasta}_Split_S 
wait



echo blastx command splitting it in 4 jobs to make it faster
    for i in {000..0$n4} ; do echo "blastx -query ${InputFasta}_Split_S$i.fa -evalue 0.0001 -max_target_seqs 100 -db nr -num_threads 8 -outfmt '7 qseqid qlen sseqid pident length mismatch gapopen qstart qend sstart send ppos evalue bitscore score' -out ${InputFasta}_blastx$i.csv" ; done > ${InputFasta}_Job1.sh


    for i in {0$n41..$n2} ; do echo "blastx -query ${InputFasta}_Split_S$i.fa -evalue 0.0001 -max_target_seqs 100 -db nr -num_threads 8 -outfmt '7 qseqid qlen sseqid pident length mismatch gapopen qstart qend sstart send ppos evalue bitscore score' -out ${InputFasta}_blastx$i.csv" ; done > ${InputFasta}_Job2.sh


    for i in {$n21..$n43} ; do echo "blastx -query ${InputFasta}_Split_S$i.fa -evalue 0.0001 -max_target_seqs 100 -db nr -num_threads 8 -outfmt '7 qseqid qlen sseqid pident length mismatch gapopen qstart qend sstart send ppos evalue bitscore score' -out ${InputFasta}_blastx$i.csv" ; done > ${InputFasta}_Job3.sh


    for i in {$n431..$n} ; do echo "blastx -query ${InputFasta}_Split_S$i.fa -evalue 0.0001 -max_target_seqs 100 -db nr -num_threads 8 -outfmt '7 qseqid qlen sseqid pident length mismatch gapopen qstart qend sstart send ppos evalue bitscore score' -out ${InputFasta}_blastx$i.csv" ; done > ${InputFasta}_Job4.sh

wait


echo Head the PBS commands to the Job files 
    for i in {1..4} 
        do 
        cat ${Head} ${InputFasta}_Job$i.sh | sed "s/BlastJob/BlastJob_$i/g" > ${InputFasta}_BlastJob$i.sh 
        done
但我在剧本中得到的只是:

blastx -query TEST_Split_S{000..050}.fa -evalue 0.0001 -max_target_seqs 100 -db nr -num_threads 8 -outfmt '7 qseqid qlen sseqid pident length mismatch gapopen qstart qend sstart send ppos evalue bitscore score' -out TEST_blastx{000..050}.csv
有人能帮我解决这个问题吗? 如果在脚本外部使用for循环,则效果很好

感谢您的帮助

支架扩展很早就开始了

参数扩展发生在稍后,因此不能以控制大括号扩展的方式使用变量或其他参数

展开顺序为:大括号展开、平铺展开、, 参数、变量和算术展开及命令 替换(以从左到右的方式完成)、分词和 路径名扩展

这将防止像{000..0$n4}中的i的
这样的语句;不要按预期工作

另外,一定要记住
-v
-x
参数,以显示实际执行的命令。

大括号扩展发生得很早

参数扩展发生在稍后,因此不能以控制大括号扩展的方式使用变量或其他参数

展开顺序为:大括号展开、平铺展开、, 参数、变量和算术展开及命令 替换(以从左到右的方式完成)、分词和 路径名扩展

这将防止像{000..0$n4}中的i的
这样的语句;不要按预期工作


另外,一定要记住
-v
-x
参数以显示实际执行的命令。

解决方法可能是
以$(eval echo{000..0$n4})表示i;pre eval用适当的值(50?)替换
0$n4
,然后
eval
{000..050}
上重新进行大括号扩展,给出单独的值。注意:
eval
通常是危险的。但是,如果像
$n4
这样的变量保证包含数字,那么这完全是一种良性的使用。谢谢你的提示。我一定会尝试使用eval。谢谢你的提示!谢谢你的解释。现在一切都正常了,我使用了-x命令进行调试。解决方法可能是I in$(eval echo{000..0$n4});pre eval用适当的值(50?)替换
0$n4
,然后
eval
{000..050}
上重新进行大括号扩展,给出单独的值。注意:
eval
通常是危险的。但是,如果像
$n4
这样的变量保证包含数字,那么这完全是一种良性的使用。谢谢你的提示。我一定会尝试使用eval。谢谢你的提示!谢谢你的解释。现在一切正常,我使用-x命令进行调试。
blastx -query TEST_Split_S{000..050}.fa -evalue 0.0001 -max_target_seqs 100 -db nr -num_threads 8 -outfmt '7 qseqid qlen sseqid pident length mismatch gapopen qstart qend sstart send ppos evalue bitscore score' -out TEST_blastx{000..050}.csv