6
votes

I am new to TCL scripting and shell scripting. I want to invoke a TCL script from the shell script. I have tried as below.

#!/bin/sh

for i in {1..5}
do
   my_script
   test_script
done

If I run the script, it is throwing error as follows,

./sample.sh: line 5: my_script: command not found
./sample.sh: line 5: test_script: command not found

Can anyone help me out with this ?

Thanks in advance.

3

3 Answers

7
votes

If they cannot be found in your $PATH you have to provide a path to your scripts, e.g.:

./my_myscript         # current directory
/path/to/test_script  # absolute path
7
votes

If you haven't made your script executable (with chmod +x) then you need to use:

tclsh my_script.tcl

Or maybe tclsh8.5 /path/to/script.tcl or many variations on that.

If you have made the script executable, check that the directory containing the script is on your PATH (if not, use the full filename of the script or adjust your PATH) and that you've got a suitable #! line. The usual recommended one is:

#!/usr/bin/env tclsh8.5

as that will search your path for the tclsh8.5 executable instead of hard-coding it.

0
votes

From man tclsh. I guess the second block answers your question.

If you create a Tcl script in a file whose first line is #!/usr/local/bin/tclsh then you can invoke the script file directly from your shell if you mark the file as executable. [...]

An even better approach is to start your script files with the following three lines:

 #!/bin/sh
 # the next line restarts using tclsh \
 exec tclsh "$0" ${1+"$@"}

This approach has three advantages over the approach in the previous paragraph [...]

You should note that it is also common practice to install tclsh with its version number as part of the name.This has the advantage of allowing multiple versions of Tcl to exist on the same system at once, but also the disadvantage of making it harder to write scripts that start up uniformly across different versions of Tcl.