我正在创建(我原以为是)一个简单的脚本来检查当前目录,该目录包含名称更多的目录;

SAMPLE_ANN-A10, SAMPLE_ANN-B4 etc.
SAMPLE_NEM-E7, SAMPLE_NEM-H2, etc.
SAMPLE_TODE-H02 etc. etc.


我想为每个样本分配一个QUERY变量并运行一个命令。所有TODE将使用相同的变量,所有NEM将使用相同的变量,而所有ANN将相同。

这是我当前的错误消息脚本。感谢您的关注。



#!/bin/bash

for dir in $@
do
QUERY=''
    if $dir == SAMPLE_ANN*/
        then
            $QUERY=annelids.fasta
    elif $dir == SAMPLE_NEM*/
        then
            $QUERY=nemertea.fasta
    else
        $QUERY=nematode.fasta
    fi

    echo $QUERY #used to check if the variable was set correctly

nohup blastn -query $QUERY -subject $dir/spades_output/contigs.fasta -out $dir/spades_output/mito_blast

done




#command from linux --> ./auto_mito_blast.sh SAMPLE_ANN-B4




#error message :

#./auto_mito_blast.sh: line 7: Sample_ANN-B4/: Is a directory
#./auto_mito_blast.sh: line 10: Sample_ANN-B4/: Is a directory
#./auto_mito_blast.sh: line 14: =nematode.fasta: command not found


谢谢,

最佳答案

双括号[[应该做的工作。 =>

for dir in $@
do
    QUERY=''
    if [[ $dir == SAMPLE_ANN* ]]
        then
            QUERY=annelids.fasta
    elif [[ $dir == SAMPLE_NEM* ]]
        then
            QUERY=nemertea.fasta
    else
        QUERY=nematode.fasta
    fi
    echo $QUERY #used to check if the variable was set correctly
done


ATM:您只是遍历所有给定的参数,但是据我所知,您想遍历当前目录中的所有目录,就像这样:

for dir in ./*


还需要一些是dir检查。
另一种方法是使用find like

find . -type d -depth 1 --execute yourscript {} \;

10-07 13:08
查看更多