Re: VMD/psfgen scripting: undefined variable

From: Jerome Henin (jhenin_at_cmm.chem.upenn.edu)
Date: Thu Nov 08 2007 - 23:34:55 CST

Richard,
This is a case where you have to consider carefully who parses what.
Your script goes through the shell before it is passed to Tcl, and the
shell does variable substitution, so nothing ever reaches the Tcl
interpreter. You can test this behavior from an interactive shell
session:

$ echo << over This shell variable is not defined: $nothing_at_all
> over
This shell variable is not defined:

But if you escape the dollar sign like that:
$ echo << over The shell will not substitute that one:
\$hands_off_I_am_a_Tcl_var
> over
The shell will not substitute that one: $hands_off_I_am_a_Tcl_var

Best,
Jerome

On 08 Nov 2007 22:30:12 -0600, Richard Baxter
<Richard.Baxter_at_utsouthwestern.edu> wrote:
> Dear All,
>
> Can anyone explain the following to me? An interactive vmd session:
>
> kong <10:21pm> 126% vmd -dispdev text
> Info) VMD for LINUX, version 1.8.6 (April 6, 2007)
> ..
> vmd > set x 10
> 10
> vmd > puts "the value of x is $x"
> the value of x is 10
> vmd > quit
> Info) VMD for LINUX, version 1.8.6 (April 6, 2007)
> Info) Exiting normally.
>
> Now try putting it in the following script:
> setup vmd
> which vmd
> vmd -dispdev text <<END
> set x 10
> puts "the value of x is: $x"
> quit
> END
>
> and you get:
> kong <10:21pm> 127% ./test.com
> /usr/progs/vmd-1.8/bin/vmd
> Info) VMD for LINUX, version 1.8.6 (April 6, 2007)
> ..
> 10
> the value of x is:
> Info) VMD for LINUX, version 1.8.6 (April 6, 2007)
> Info) Exiting normally.
>
> Let's try an interactive psfgen session:
> kong <10:24pm> 129% psfgen
> PSFGEN from NAMD 2.6 for Linux-i686
> % set x 10
> 10
> % puts "the value of x is $x"
> the value of x is 10
> % exit
>
> Now put that in a script:
> setup namd
> which psfgen
> psfgen <<END
> set x 10
> puts "the value of x is: $x"
> exit
> END
>
> and you get:
> /usr/progs/NAMD_2.6_Linux-i686/psfgen
> PSFGEN from NAMD 2.6 for Linux-i686
> the value of x is:
> kong <10:25pm> 132%
>
> At least the vmd script spat out the value of x, but didn't call it.
> PSFGEN didn't even return the variable value when set! I am at a loss to
> explain, expecially since I already went through the VMD and NAMD
> tutorials and those scripts worked fine.
>
> Help!
>
> Richard
>
> --
> Richard Baxter <Richard.Baxter_at_UTSouthwestern.edu>
> Howard Hughes Medical Institute
>
>

This archive was generated by hypermail 2.1.6 : Wed Feb 29 2012 - 15:45:30 CST