Bash while read line

I have a script batch_vmdgenpqr.sh which has a problem:

#!/bin/bash
while read line
do
      vmd.sh -dispdev text -e vmdgenpqr.tcl -args $line
done<file

The do line calls another program, VMD (called by vmd.sh) and it requires the values from $line, but this is not recognised by vmd. I'm not asking anyone to comment on VMD but is BASH passing on the correct variable?

[user]$ ./batch_vmdgenpqr.sh 
Info) VMD for LINUXAMD64, version 1.9.1 (February 1, 2012)
Info) http://www.ks.uiuc.edu/Research/vmd/                         
Info) Email questions and bug reports to vmd@ks.uiuc.edu           
Info) Please include this reference in published work using VMD:   
Info)    Humphrey, W., Dalke, A. and Schulten, K., `VMD - Visual   
Info)    Molecular Dynamics', J. Molec. Graphics 1996, 14.1, 33-38.
Info) -------------------------------------------------------------
Info) Multithreading available, 32 CPUs detected.
Info) Free system memory: 126641MB (98%)
Info) Creating CUDA device pool and initializing hardware...
CUDA error: invalid device symbol, CUDAClearDevice.cu line 62
Info) Detected 1 available CUDA accelerator:
Info) [0] Quadro K5000        8 SM_3.0 @ 0.71 GHz, 4.0GB RAM, KTO, OIO, ZCP
Info) Dynamically loaded 2 plugins in directory:
Info) /opt/vmd-1.9.1/plugins/LINUXAMD64/molfile
can't read "line": no such variable

It should be. Throw an echo "line: ""$line" in there for debugging.

#!/bin/bash
while read line
do
      echo "line: ""$line"
      vmd.sh -dispdev text -e vmdgenpqr.tcl -args $line
done<file

Mike

PS. VMD may want you to pass a variable name and not the value. Try eliminating the $ in $line.

First line in file "file" is PA2_2_f1010 so it is echoing correctly.

What VMD wants is the value of a variable $line which contains the first line of the file "file", namely PA2_2_f1010..

but I tried running with $line and just line, no difference.

[user]$ ./batch_vmdgenpqr.sh 
line: PA2_2_f1010
Info) VMD for LINUXAMD64, version 1.9.1 (February 1, 2012)
Info) http://www.ks.uiuc.edu/Research/vmd/                         
Info) Email questions and bug reports to vmd@ks.uiuc.edu           
Info) Please include this reference in published work using VMD:   
Info)    Humphrey, W., Dalke, A. and Schulten, K., `VMD - Visual   
Info)    Molecular Dynamics', J. Molec. Graphics 1996, 14.1, 33-38.
Info) -------------------------------------------------------------
Info) Multithreading available, 32 CPUs detected.
Info) Free system memory: 111420MB (86%)
Info) Creating CUDA device pool and initializing hardware...
CUDA error: invalid device symbol, CUDAClearDevice.cu line 62
Info) Detected 1 available CUDA accelerator:
Info) [0] Quadro K5000        8 SM_3.0 @ 0.71 GHz, 4.0GB RAM, KTO, OIO, ZCP
Info) Dynamically loaded 2 plugins in directory:
Info) /opt/vmd-1.9.1/plugins/LINUXAMD64/molfile
can't read "line": no such variable
Info) VMD for LINUXAMD64, version 1.9.1 (February 1, 2012)
Info) Exiting normally.
invalid command name "PA2_2_f1043"

Try quoting $line:

vmd.sh -dispdev text -e vmdgenpqr.tcl -args "$line"