如果目录存在则出现问题

如果目录存在则出现问题

我有以下代码:

#!/bin/bash

while read line
do
echo "line" $line
if [[ -d ../Results/${line}_Forward && -d ../Results/${line}_Reverse ]]
then

        cd ../Results/COMBI
        mkdir ./${line}_COMBI
        cd ..
        for (( win = 2; win < 20; win += 2 )); do
        printf 'The value of win is %d, now entereing inner loop\n' "$win"

        for (( per = 50; per < 100; per += 2 )); do
            printf 'Value of per is %d\n' "$per"
            merger -asequence ./${line}_Forward/${line}_Forward_Trimmed_w${win}_p${per}.fa -bsequence ./${line}_Reverse/REV_COMP/${line}_Reverse_Trimmed_w${win}_p${per}_RevComp.fa -outseq ./COMBI/${line}_COMBI/${line}_w${win}_p${per}_COMBI.fa
        done
        done
else
    echo $line "Forward or Reverse directory does not exist"
fi
done < ./Data_ORD.txt

当我运行脚本时, if 语句中包含的任何字典都会退出,但它们实际上会退出。我在 Data_ORD.txt 中的每一行得到这样的输出:

line  ORD0926
 Forward or Reverse directory does not exist

最后一个echo$line 变量不被打印。我猜想这个变量或者 if 语句有问题。

知道为什么 $line 没有在最后一个 echo 中打印并且 if 语句无法识别目录吗?

**.fa:fasta 格式,是包含 DNA 序列的纯文本格式。 **合并命令:包含在EMBOSS包“欧洲分子生物学开放软件套件”中

答案1

我正在检查两个目录是否存在。之后我创建了一个新变量,它剪切了数据文件中包含的代码: wth=echo ${line} |切-c 1-7

#!/bin/bash

while read line
do
echo "line" $line
wth=`echo ${line} |  cut -c 1-7`
echo "wth" ${wth}
if [[ -d ../Results/${wth}_Forward && -d ../Results/${wth}_Reverse ]]
then

        cd ../Results/COMBI
        mkdir ./${wth}_COMBI
        cd ..
        for (( win = 2; win < 20; win += 2 )); do
        printf 'The value of win is %d, now entereing inner loop\n' "$win"

        for (( per = 50; per < 100; per += 2 )); do
            printf 'Value of per is %d\n' "$per"
            merger -asequence ./${wth}_Forward/${wth}_Forward_Trimmed_w${win}_p${per}.fa -bsequence ./${wth}_Reverse/REV_COMP/${wth}_Reverse_w${win}_p${per}_RevComp.fa -outfile none -outseq ./COMBI/${wth}_COMBI/${wth}_w${win}_p${per}_COMBI.fa
        done
        done
else
    echo ${wth} "Forward or Reverse directory does not exist"
fi
done < ./Data_ORD.txt

现在脚本可以运行了。似乎直接调用 $line 作为变量并不是一个好主意,因为可能存在一些看不见的空格。

相关内容