如何通过传递参数来获取脚本文件?
假设我有一个 tcl 脚本,我想将一些参数传递给第一个 tcl 中来源的第二个脚本文件:
#first tcl file
source second.tcl
我想控制来自 first.tcl 的 secondary.tcl 的流程,并且我读到 tcl 源不接受论据。我想知道那时我该怎么办。
Say I have a tcl script and I want to pass some arguments to the second script file which is being sourced in the first tcl:
#first tcl file
source second.tcl
I want to control the flow of second.tcl from first.tcl and I read that tcl source does not accept arguments. I wonder how I can do then.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
source
不接受任何其他参数。但您可以使用(全局)变量来传递参数,例如:第二个 TCL 文件可以引用该变量,例如:
备注:
获取文件意味着源脚本的内容在当前上下文中执行。这意味着源脚本可以访问该上下文中存在的所有变量。上面的代码等同于:
source
does not accept any additional arguments. But you can use (global) variables to pass arguments, e.g.:The second TCL file can reference the variable, e.g.:
Remark:
Sourcing a file means that the content of the sourced script is executed in the current context. That means that the sourced script has access to all variables existing in that context. The above code is the same as:
关于“::”的事情 - 请参阅此处的解释(抱歉,我还没有足够的代表来发表评论)。
我还应该补充一点,最初的问题讨论了一个看起来很奇怪的问题:似乎最好在第二个源文件中提供一个特定的过程,该过程将设置与该脚本定义的状态相关的状态。
像这样的事情:
根据某些全局变量使
[source]
表现不同对我来说看起来太晦涩了。当然,你可能有正当理由这样做,但无论如何......Regarding the "::" thing -- see the explanation here (sorry, I don't have enough rep. to leave comments yet).
I should also add that the original question discusses a problem which appears to be quite odd: it seems that it could be better to provide a specific procedure in your second source file that would set up a state pertaining to what is defined by that script.
Something like:
Making
[source]
behave differently based on some global variables looks too obscure to me. Of course you might have legitimate reasons to do this, but anyway...