0

I have this script to do a certain actions on my files. Maybe I have a problem with the variable $dir because I don't know what is the right character when I use it on the script.

for dir in *; do 
      cd $dir; flapwater -lp ../../ligands/"$dir.mol2" ../A2a1071_PEP_REC.pdb "A2a1071_$dirDock_Complex.pdb"; 
      flapwater -w-auto -i "A2a1071_"$dirDock_Complex.pdb" -o "WF_$dir.pdb" -gl ../../ligands/"$dir.mol2" -gr 6 > WF.log; 
      cd .. ; 
done 

Example:

If the variable is $dir = 4a the script should be:

for dir in *; do 
     cd $dir; flapwater -lp ../../ligands/4a.mol2 ../A2a1071_PEP_REC.pdb A2a1071_4aDock_Complex.pdb; 
     flapwater -w-auto -i A2a1071_4aDock_Complex.pdb -o WF_4a.pdb -gl ../../ligands/4a.mol2 -gr 6 > WF.log; 
     cd .. ; 
done

Could someone explain me the write use of $dir please?

0

1 Answer 1

1

Bash can't tell whether $dirDock_Complex is a variable name or just a part of it (so it always uses the longest possible name). Use curlies to separate the variable name.

Also, double quote the variable so cd works even if the directory name contains whitespace.

for dir in * ; do
    cd -- "$dir" || continue # Double quotes.
    flapwater -lp ../../ligands/"$dir.mol2" ../A2a1071_PEP_REC.pdb "A2a1071_${dir}Dock_Complex.pdb"  # Curlies.
    flapwater -w-auto -i "A2a1071_${dir}Dock_Complex.pdb" -o "WF_$dir.pdb" -gl "../../ligands/$dir.mol2" -gr 6 > WF.log # curlies
    cd .. || break
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .