1

I don't program in TCL but I do use them such as tkcvs and tkdiff. I notice that they declare themselves as shell script

#!/bin/sh
#-*-tcl-*-

What's more, running them through tclsh doesn't work either and I get error like this:

Initialization failed

The second line in the header baffles me too because AFAIK, shell only looks at the #! line. How's this working?

1

1 Answer 1

3

Tcl scripts are normally setup to run using slightly more than you have shown. It is typically and most robustly done like the following:

#!/bin/sh
# \
exec tclsh "$0" ${1+"$@"}

They use the shell initially because there was no standard installation location for tcl so the location could not be relied on. Instead, by starting the system shell and using that to start the tclsh executable you could be certain to run the installed tclsh as long as it was present on the PATH. The shell evaluates the script and sees the exec tclsh "$0" which causes it to execute the installed tclsh binary and pass it $0 (the script file name) as the first argument, which re-runs the script using the tcl interpreter.

The second line in my example comments out the third line when the script is evaluated by the tcl interpreter. The backslash causes the second and third lines to be treated as a single comment when read by tclsh so that tcl doesn't try and run the exec again.

In your snipped the # -*-tcl-*- is marker to indicate the mode to be used by emacs when editing the file. See the documentation.

There is not really enough to go on for the error message. It doesn't seem to be from the Tcl interpreter itself. (That is 'git grep' in the tcl sources does not match that string).

Sign up to request clarification or add additional context in comments.

2 Comments

Indeed you are right. Further down the file there is "exec wish $0"
We prefer #!/usr/bin/env tclsh these days. Simpler in anything remotely like a normal case…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.