我想從Bash while循環中調用Python腳本。但是,我不太清楚如何正確使用Bash的while循環(也許是變量)語法。我正在尋找的行爲是,雖然文件仍然包含行(DNA序列),但我調用Python腳本來提取序列組,以便另一個程序(dialign2)可以對齊它們。最後,我將對齊添加到結果文件中。注意:我不想遍歷文件。爲了讓Bash while循環正常工作,我應該更改哪些內容?我還想確保while循環將重新檢查每個循環中正在更改的file.txt。這是我的嘗試:Bash while循環調用Python腳本
#!/bin/bash
# Call a python script as many times as needed to treat a text file
c=1
while [ `wc -l file.txt` > 0 ] ; # Stop when file.txt has no more lines
do
echo "Python script called $c times"
python script.py # Uses file.txt and removes lines from it
# The Python script also returns a temp.txt file containing DNA sequences
c=$c + 1
dialign -f temp.txt # aligns DNA sequences
cat temp.fa >>results.txt # append DNA alignements to result file
done
謝謝!
你可能需要一個更清楚一點什麼沒有做什麼工作的? – Singletoned 2010-03-01 23:35:12
'WC -l file.txt'將返回像'100 file.txt',如果你真的想使用wc,你需要提取數字。例如。 'wc -l file.txt | cut -f1 -d''' – MattH 2010-03-01 23:40:41
爲什麼不從Python腳本調用Python? – Alex 2010-03-02 00:06:05