Tcl 脚本无法从 bash shell 脚本执行

发布于 2024-12-11 09:40:27 字数 469 浏览 0 评论 0原文

我对 bash shell 脚本和 tcl 脚本有一个相对奇怪的问题,从 shell 脚本中调用。

从角度来看,我有一个 shell 脚本,它生成一些其他 shell 脚本,以及 tcl 脚本。一些生成的 shell 脚本使用 tclsh 命令调用 tcl 脚本。 文件被创建并存储在一个目录中,该目录也是由初始 shell 脚本创建的,该目录生成文件以及要存储这些文件的文件夹。

问题在于生成的 shell 脚本,它调用 tclsh 来运行 tcl 脚本。即使文件生成了并且shell脚本有执行的权限,shell的响应也是找不到shell脚本中嵌入的tcl文件。

但是,该文件存在,我可以使用 vi 和 gedit、RHEL 9.0 或 Centos 5.7 平台打开它。但是,当我从创建的目录中取出相同的 shell 脚本时,不会出现此错误。你能提出任何想法吗?我还检查了目录权限,但它们看起来没问题。我还检查了 shell 脚本中是否有多余的字符,但没有找到任何内容。

I have a relatively strange problem with bash shell scripts and tcl scripts, invoked from within the shell scripts.

In perspective, I have a shell script that generates some other shell scripts, as well as tcl scripts. Some of the generated shell scripts invoke tcl scripts with tclsh command.
The files are created and stored in a directory, also created by the initial shell scripts, that generates the files and the folders where these are to be stored.

The problem is with the generated shell scripts, which invoke tclsh to run a tcl script. Even if the files are generated and the shell scripts have the permissions to be executed, the response from the shell is that the tcl file embedded in the shell script cannot be found.

However, the file exists and I can open it with both vi and gedit, RHEL 9.0 or Centos 5.7 platforms. But, when I take the same shell script out of the created directory, this error does not appear. Can you please suggest any idea? I checked also directory permissions, but they seem ok. I also checked the shell script for extra characters, but I did not find anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅沫记忆 2024-12-18 09:40:27

从你的描述中很难判断到底出了什么问题;您遗漏了精确诊断问题实际所需的所有信息。但是...

您的 PATH 上有一个 tclsh,但尽管已 chmodded 为可执行,但您的脚本并未运行?这意味着您的 #! 行有问题。当前的最佳实践是您使用这样的东西:

#!/usr/bin/env tclsh

它将在您的 PATH 中搜索 tclsh 并使用它,它比任何其他替代方法都要容易得多。

另一件可能导致问题的事情是,如果您的 Tcl 程序包含:

package require Tcl 8.5

而路径上的 tclsh 使用的 Tcl 版本是 8.4。我已经多次看到这种情况,如果这是您的问题,您需要确保安装了正确的 Tcl rpm 将您的 #! 行更新为此:

#!/usr/bin/env tclsh8.5

与 Tcl 8.6 类似,但在这种情况下,您可能还需要从源代码构建自己的版本并将其安装在合适的位置。 (Tcl 8.6 仍然只适合专家。)


(问题在于 RHEL 以及跟踪 RHEL 的 Centos 在涉及 Tcl 时非常保守。其原因并不真正不过与这个答案密切相关。)

It's hard to tell what exactly is going wrong from your description; you leave out all the information actually required to diagnose the problem precisely. However…

You have a tclsh on your PATH, but your script isn't running despite being chmodded to be executable? That means that there's a problem with your #! line. Current best practice is that you use something like this:

#!/usr/bin/env tclsh

That will search your PATH for tclsh and use that, and it's so much easier than any of the alternative contortions.

The other thing that might be causing a problem is if your Tcl program contains:

package require Tcl 8.5

And yet the version of Tcl used by the tclsh on the path is 8.4. I've seen this a number of times, and if that's your problem you need to make sure that the right Tcl rpm is installed and to update your #! line to this:

#!/usr/bin/env tclsh8.5

Similarly for Tcl 8.6, but in that case you might need to build your own from source as well and install that in a suitable location. (Tcl 8.6 is still only really for people who are specialists.)


(The issue is that RHEL — and Centos too, which tracks RHEL — is very conservative when it comes to Tcl. The reasons for this aren't really germane to this answer though.)

二货你真萌 2024-12-18 09:40:27

问题可能只是因为您没有“.”那么简单吗?在你的路径中?如果不是像“myscript.tcl”那样调用您的脚本,而是像“./myscript.tcl”或“/absolute/path/to/myscript.tcl”那样调用它怎么办?

Could the problem be as simple as the fact that you don't have "." in your PATH? What if instead of calling your script like "myscript.tcl" you call it like "./myscript.tcl" or "/absolute/path/to/myscript.tcl"?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文