有没有办法将参数传递给 TCL 中使用 eval 源运行的脚本?
我有一个脚本调用:
eval source \{$scriptfile\}
其中 $scriptfile 是另一个 TCL 脚本。有没有办法向脚本传递参数?我想做类似的事情:
set sampleData "ID=14678934"
eval source \{$scriptfile\} $sampleData
我知道这是不允许的,但是有没有办法将数据传递到使用 eval 源执行的脚本?
I have a script that calls:
eval source \{$scriptfile\}
where $scriptfile is another TCL script. Is there way to pass parameters to the script? I'd like to do something like:
set sampleData "ID=14678934"
eval source \{$scriptfile\} $sampleData
I know that this isn't allowed but, is there a way to pass data to a script that is being executed using eval source?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个可怕的开始。调用您正在采购的脚本内的过程要干净得多。
That's a horrible practice to start. It's much cleaner to call a proc that is within the script you're sourcing.
解决方案在 Tclers Wiki 中的以下文章中给出:带有参数的源 和 SrcFile.
我最喜欢的解决方案是
srcfile
:这种方法的唯一缺点是它会修改
argv
,所以你必须确保在其余部分不需要它脚本,或备份并恢复它。The solution is given in the Tclers Wiki, in the following articles: source with args and SrcFile.
The solution I like the most is
srcfile
:The only drawback of this approach is that it will modify
argv
, so you have to make sure you will not need it in the rest of the script, or backup and restore it.