问题描述
我尝试了以下操作:
set timeout -1
spawn $env(SHELL)
match_max 100000
send -- "ssh somewhere@addr"
expect "*"
for { set i 0 } { $i < [array size env] } { incr i } {
send -- "echo env($i) = $env($i)"
expect "*"
}
send -- "env > foo\r"
expect "*"
send -- "^D"
expect eof
以上操作失败,并出现以下错误:
no such variable
(read trace on "::env(0)")
invoked from within
"send -- "echo env($i) = env($i)""
("for" body line 2)
invoked from within
"for { set i 0 } { $i < [array size env] } { incr i } {
send -- "$::env($i)"
expect "*"
}"
(file "./script.exp" line 52)
我将通过重新采购rc
文件来解决系统问题;我只想将我设置的未知变量集(相对于脚本)传输到远程执行环境。
这可能吗,我不熟悉TCL(总初学者)?
解决方法
Tcl arrays更像是键和值的字典,而不是按数字索引的列表。您可以使用var body: some View {
VStack {
SearchBar(text: $searchViewModel.searchText)
let displayContacts = searchViewModel.searchText.count == 0 ? contacts : searchResults
List {
ForEach(displayContacts,id: \.identifier) { contact in
cellWithContact(contact)
}
}
}
}
@ViewBuilder
private func cellWithContact(_ contact: CNContact) -> some View {
let displayName: String? = CNContactFormatter.string(from: contact,style: .fullName)
HStack() {
Text(displayName ?? "No Name")
Spacer()
Button {
// invite
} label: {
Text("Invite")
}
}
}
获取键列表,并使用[array names env]
遍历它们:
foreach