如何在TCL中获得一个带空格的单个字符串变量以解释为多个参数?我无法更改proc定义。
这是我的意思的示例:
set my_options ""
if { "$some_condition" == 1 } {
append my_options " -optionA"
}
if { "$some_other_condition" == 1 } {
append my_options " -optionB"
}
set my_options [string trim $my_options]
not_my_proc ${my_options} ;# my_options gets interpreted as a single arg here and causes a problem:
# Flag '-optionA -optionB' is not supported by this command.
答案 0 :(得分:1)
在这里使用argument expansion语法:
not_my_proc {*}$my_options
# ..........^^^
尽管我建议使用列表而不是字符串:
set my_options [list]
lappend my_options {-option1}
lappend my_options {-option2 "with a parameter"}
not_my_proc {*}$my_options