For loop to run external program

Hi, I was hoping for help with a for loop to run a program (vina) repeatedly using all the files in a folder as input. Currently my code looks like this:

#!/bin/bash
FILES=/home/afalk/Desktop/battest/*.pdbqt
for f in $FILES do
vina --config /home/afalk/Desktop/A.txt --ligand "$f".pdbqt
done

vina simply runs as "vina" in the terminal and this code is my attempt at translating a working batch file I had for windows. Whenever I try to run this, and after endless changes to the syntax all I get is "line 4: syntax error near unexpected token `vina'". Can anyone see what I'm doing wrong?

You nearly had it! :slight_smile: You didn't put a ; or newline before the 'do', though.

You don't need to put the filenames in a variable. That could actually be bad -- $FILES will split "file name.pdbgt file2.pdbgt" into "file", "name.pdbgt", "file2.pdbgt". "for FILE in *" won't.

You also don't need to put the ".pdbgt" back on the end, it never left :wink:

#!/bin/bash
for f in /home/afalk/Desktop/battest/*.pdbqt
do
        vina --config /home/afalk/Desktop/A.txt --ligand "$f"
done

Thank you, except now it says "line 5: vina: command not found" if I change the code to

#!/bin/bash
FILES=/home/afalk/Desktop/battest/*.pdbqt
for f in $FILES 
do
$vina --config /home/afalk/Desktop/A.txt --ligand "$f".pdbqt
done 

it returns "line 5: --config: command not found" config is an internal command for vina.

Well, it means what it says: it can't find vina.

If it's in the current directory, you have to run it as ./vina

Otherwise, try whereis vina, that might tell you where it is. If it's in an odd location you'd run it as /path/to/vina

You don't want $vina, that's how you'd use a variable named vina. That must be blank, causing the line to become --config ... and of course it can't find any file to run named '--config' either.

Alright, had to write out the full pathway. Thank you so much!

It is trying to run the command, --config, because $vina is empty.