James Stroud <xtald...@gmail.com> writes:
> I inserted the echo to see if the variable was defined at that
> point. The variable wasn't found to be defined at the script at the
> point of  the execute command so I made the echo to see if it was
> before that.  The line continuation is from the CCP4 code, it is not
> my doing. I  kept it intact to preserve the script as much as possible
> to see if it  made a difference at the point of the echo, which was
> meant to be  positionally equivalent to the exec statement.

But when you inserted the echo statement, you made the exec statement
visible to Tcl. This is in fact a (dirty) trick to reuse a shell script
as a Tcl program. Try this instead:

   #!/bin/sh
   # Start ccp4i interface
   # \
   echo CCP4I_TCLTK is $CCP4I_TCLTK;exec ${CCP4I_TCLTK}/bltwish "$0" -- 
${1+"$@"}
   source [file join $env(CCP4I_TOP) bin ccp4i.tcl]

The trick with the "# \" incantation is this: 

When the Bourne shell (/bin/sh) executes this script, it ignores the
first three lines as comment, then reads the fourth line and does the
exec, which starts Tcl and tells it to execute the vary same file
"$0". The remainder of the script is then not read by the shell. Tcl,
however, when reading the script again, sees a continuation character at
the end of the third line, then assumes the fourth line is a
continuation of the comment (if you did not accidentally leave
whitespace after the backslash), and continues execution with the fifth
line.

When you inserted the echo statement, it became the line being ignored
in Tcl, but Tcl then tried to execute the exec statement and interpreted
${CCP4I_TCLTK} as a Tcl variable reference to a variable that does not
exist in Tcl (it exists in the environment, but then you need to access
it through $env).

The only documentation I could find on that on the internet seems to be
a Usenet posting from 1998 (quoted in http://wiki.tcl.tk/812) to which
other people seem to usually react "this should be posted somewhere
prominently"...

-Christoph

-- 
| Christoph Best         <b...@ebi.ac.uk>           http://www.ebi.ac.uk/~best
| European Bioinformatics Institute, Cambridge, UK             +44-1223-492649

Reply via email to