user19619903
user19619903

Reputation: 151

Call variable inside bash script

I am attempting to create a variable 'a' that takes the first and only line of a file containing three coordinates with commas between each, as a line. Then, I am trying to call this variable to set is as an input to run a second program. I am attempting to do this from the same script, as follows.

a=$(cut -f 2 aver.line.comma.dat)
$MGLROOT/bin/pythonsh ~/Downloads/autodockZN_filesAndTutorial/prepare_gpf4zn.py -l ligand.pdbqt -r protein_tz.pdbqt  -o protein_tz.gpf -p npts=500,500,500 -p gridcenter=echo "$a"  -p parameter_file=AD4Zn.dat

I have all the needed input files. I want to make sure gridcenter will be equal to this variable a.

my variable a looks as follows:

95.8916,53.8569,28.052

Does someone know a way of achieving this? I tried to set gridcenter=$a, and gridcenter=(echo $a) with no luck.

Thank you!

Upvotes: 0

Views: 303

Answers (1)

glenn jackman
glenn jackman

Reputation: 246774

You don't need to "call" or "execute" a variable. To use it, just expand it:

... -p gridcenter="$a" ...

Side note: when you have loads of arguments, it can aid readability to store them in an array

prepare="$HOME"/Downloads/autodockZN_filesAndTutorial/prepare_gpf4zn.py
args=(
    -l ligand.pdbqt
    -r protein_tz.pdbqt 
    -o protein_tz.gpf
    -p npts=500,500,500
    -p gridcenter="$(cut -f 2 aver.line.comma.dat)" 
    -p parameter_file=AD4Zn.dat
}
"$MGLROOT"/bin/pythonsh "$prepare" "${args[@]}"

Upvotes: 4

Related Questions