Question: I would like to call a Python script from within a Bash while loop. However, I do not understand very well how to use appropriately the while loop (and maybe variable) syntax of the Bash. The behaviour I am looking for is that, while a file still contains lines (DNA sequences), I am calling a Python script to extract groups of sequences so that another program (dialign2) can align them. Finally, I add the alignments to a result file. Note: I am not trying to iterate over the file. What should I change in order for the Bash while loop to work? I also want to be sure that the while loop will re-check the changing file.txt on each loop. Here is my attempt:

```
#!/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

```

Thanks!

Answer: 
try `-gt` to eliminate the shell metacharacter `>`

```
while [ `wc -l  file.txt`  -gt 0 ]
do
    ...
    c=$[c + 1]
done

```
@OP if you want to loop through a file , just use while read loop. Also, you are not using the variables $c as well as the line. Are you passing each line to your Python script? Or you just calling your Python script whenever a line is encountered? (your script going to be slow if you do that)

```
while true
do
    while read -r line
    do
       # if you are taking STDIN in myscript.py, then something must be passed to
       # myscript.py, if not i really don't understand what you are doing.

       echo "$line" | python myscript.py > temp.txt
       dialign -f temp.txt # aligns DNA sequences
       cat temp.txt >>results.txt
    done <"file.txt"
    if [ ! -s "file.txt" ]; break ;fi
done  

```

Lastly, you could have done everything in Python. the way to iterate "file.txt" in Python is simply

```
f=open("file.txt"):
for line in f:
    print "do something with line"
    print "or bring what you have in myscript.py here"
f.close()

```