Bash

如果目錄存在問題

  • January 15, 2017

我有以下程式碼:

#!/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 沒有在最後一個回顯中列印並且 if 語句無法辨識目錄嗎?

**.fa:fasta 格式,是包含 DNA 序列的純文字格式。**merger 命令:包含在 EMBOSS 包“歐洲分子生物學開放軟體套件”中

我正在檢查兩個目錄是否存在。之後我創建了一個新變數,用於剪切數據文件中包含的程式碼: 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 作為變數呼叫並不是一個好主意,因為可能會有一些看不見的空格。

引用自:https://unix.stackexchange.com/questions/337548