rehmanz has asked for the wisdom of the Perl Monks concerning the following question:

The "." followed by a shell script name allows one to execute script in the current shell in order to access all the variables of the shell. For example:

. myScript.sh
I am looking for a similar command in TCL and I cannot find it. Is there a way to use the "exec" command to execute a program in the same shell? Please let me know.

Replies are listed 'Best First'.
Re: Equivalent Dot Command in TCL
by Corion (Patriarch) on Oct 09, 2010 at 06:55 UTC

    The closest equivalent to the "dot" (resp. source) shell command in Perl is do. If you only want to load subroutines from external files, require and use are more common.

Re: Equivalent Dot Command in TCL
by ww (Archbishop) on Oct 09, 2010 at 01:05 UTC
    Assuming you're talking about Perl's exec, see
    perldoc -f exec
    and see also backticks and system.
Re: Equivalent Dot Command in TCL
by andal (Hermit) on Oct 11, 2010 at 07:16 UTC

    Well. The question is about TCL and not about perl. More than that, it is about interaction of TCL with shell :) Anyway. I don't believe you need such a "dot-command" for executing TCL. It is always executed in the context of the current shell. Just make sure you export the desired variables, or add them to the command line. For example

    bash$ MY_ENVIRONMENT_1=some_val MY_ENVIRONMENT_2=other_val ./my_tcl_sc +ript

    The "dot-command" for shell is needed, because otherwise new shell interpreter is started. The #!/bin/sh on the first line of the script requests this. In TCL scripts (as well as perl scripts) the first line requests some different executable, not the new shell (normally) so, no new shell is started.

Re: Equivalent Dot Command in TCL
by cdarke (Prior) on Oct 11, 2010 at 13:32 UTC
    exec in TCL behaves differently to exec in Perl and most shells. In TCL, exec creates a subprocess and is a general function for running programs. exec in Perl (and others, including C) switches programs within the same process - it does not create a new process. In Perl there is no return from a successful exec.

    As others have said, you can use do or, better, write a module and use use.