"exec source <script>" does not work in tcl "exec source <script>" does not work in tcl unix unix

"exec source <script>" does not work in tcl


If the script you were given is a cshell script, you can exec it like this:

exec /bin/csh $path_to_script

In effect, this is what the 'source' command does from within an interactive shell. It's not clear whether this is really what you want to do or not (not exactly, but close enough for this discussion).

The reason you can't exec the source command is that exec will only work on executable files (hence the name 'exec'). The source command isn't implemented as an exectuable file, it is a command built-in to the shell. Thus, it can't be exec'd.

If you really feel the need to exec the source command or any other built-in command you can do something like this:

exec /bin/csh -c "source $path_to_script"

In the above example you are execing the c shell, and asking it to run the command "source ". For the specific case of the source command, this doesn't really make much sense.

However, I'm not sure any of this will really do what you expect. Usually if someone says "here's some commands, just do 'source ', it usually just defines some aliases and whatnot to be used from within an interactive shell. Those aliases won't work from within Tcl.


source in csh, like . in bash, executes a script without spawning a new process.

The effect is that any variable that is set in that script is available in current csh session.

Actually, source is a built-in command of csh, thus not available from tcl exec, and using exec without source would not give the specific source effect.

There is no simple way to solve your problem.


source load the source file

you should do:

source <script path>

If you want to execute it, then you need to call the main proc.

another option would be to do:

exec [info nameofexecutable] <scritp path>