gpt4 book ai didi

bash - 将参数从命令行传递到 tcl 脚本

转载 作者:行者123 更新时间:2023-11-29 09:04:39 41 4
gpt4 key购买 nike

我有一个 TCL 脚本,其中有许多定义为实参的参数。我打算创建一个作业文件,我可以在其中执行具有不同参数组合的 .tcl 脚本,而无需手动干预。

我的意思是:

作业文件(run.sh):

./main.tcl arg1 arg2 arg3 arg4 
./main.tcl arg1 arg3 arg5

现在我希望能够将 run.sh 中提到的每次运行的命令行参数数组“argv”作为数组传递到 main.tcl 脚本中,以便在执行之前在脚本中相应地设置选项。

有没有办法链接 .sh 脚本和 .tcl 脚本?

最佳答案

根据 online document here :

The method by which numbers can be passed into, and used by a script,is as follows.

argc argv argv0

All Tcl scripts have access to three predefined variables.$argc - number items of arguments passed to a script.$argv - list of the arguments.$argv0 - name of the script.

To use the arguments, the script could be re-written as follows.

if { $argc != 2 } {
puts "The add.tcl script requires two numbers to be inputed."
puts "For example, tclsh add.tcl 2 5".
puts "Please try again."
} else {
puts [expr [lindex $argv 0] + [lindex $argv 1]]
}

关于bash - 将参数从命令行传递到 tcl 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24376421/

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