简体   繁体   English

如何从shell脚本运行TCL脚本?

[英]How to run a TCL script from shell script?

I am new to TCL scripting and shell scripting. 我是TCL脚本和shell脚本的新手。 I want to invoke a TCL script from the shell script. 我想从shell脚本调用TCL脚本。 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. 提前致谢。

If they cannot be found in your $PATH you have to provide a path to your scripts, eg: 如果在$PATH找不到它们,则必须提供脚本的路径,例如:

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

If you haven't made your script executable (with chmod +x ) then you need to use: 如果您还没有使脚本可执行(使用chmod +x ),那么您需要使用:

tclsh my_script.tcl

Or maybe tclsh8.5 /path/to/script.tcl or many variations on that. 或者也许是tclsh8.5 /path/to/script.tcl或其中的许多变体。

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 #! 如果您使脚本可执行,请检查包含该脚本的目录是否在您的PATH (如果没有,请使用脚本的完整文件名或调整您的PATH )并确保您拥有合适的#! 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. 因为这将搜索你的路径以获取tclsh8.5可执行文件而不是硬编码。

From man tclsh . 来自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. 如果在第一行是#!/usr/local/bin/tclsh的文件中创建Tcl脚本,那么如果将文件标记为可执行文件,则可以直接从shell调用脚本文件。 [...] [...]

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. 您应该注意,通常的做法是安装tclsh及其版本号作为名称的一部分。这样做的好处是允许同时在同一系统上存在多个版本的Tcl,但也有一个缺点,就是让它变得更难编写在不同版本的Tcl中统一启动的脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM