gpt4 book ai didi

tcl - 在 TCL 命令行中传递参数

转载 作者:行者123 更新时间:2023-12-03 00:12:50 28 4
gpt4 key购买 nike

来自Tcl FAQ for Windows :

To run a console script, invoke the tclsh.exe program, passing it the path to the script file. Any additional arguments on the command line are passed as a list to the script in the argv global variable

# File printargs.tcl
foreach arg $::argv {puts $arg}

We can invoke this script from the command line:

c:\> tclsh printargs.tcl first "second arg"
first
second arg
c:\>

我能做到。
但这是如何运作的呢?
争论进展如何?

注意:我是初学者。如果我没有达到标准,抱歉。

最佳答案

如果您了解对 Tcl 的调用是如何工作的,那么您应该知道在以下行中给出了两个参数,即 first 和“second arg”(需要引号以确保第二个参数由两个单词组成:

c:\> tclsh printargs.tcl first "second arg"

然后执行以下指令:

foreach arg $::argv {puts $arg} 

...利用控制结构:

foreach <variable-name> <list> { <commands> }

所以,arg是变量名(读取这个变量需要添加$符号 -> $arg)。

$::argv实际上是一个全局变量,包含命令行参数列表(包含第一个和“第二个arg” )。

puts $arg 是将 $arg 变量的内容打印到屏幕的命令。

但是可能还有更简单的例子可以开始。如果您想扩展您的技能,请阅读一些 Tcl/Tk 教程或书籍。 Brent Welch 的使用 Tcl/Tk 进行实用编程是一个好的开始。

关于tcl - 在 TCL 命令行中传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15797747/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com