【发布时间】:2021-04-22 14:39:58
【问题描述】:
在这个链接上,我已经阅读了 for loop management for except https://tcl.tk/man/tcl8.6/TclCmd/for.htm
如果你调用 expect 并将代码粘贴进去,你会得到正确的行为:
@gigi:~$ expect
expect1.1> for {set x 0} {$x<10} {incr x} {
puts "x is $x"
}+> +>
x is 0
x is 1
x is 2
x is 3
x is 4
x is 5
x is 6
x is 7
x is 8
x is 9
expect1.2>
如果你从 bash 脚本传递它,它会出错:
^@gigi:~expect -d << EOD
> for {set x 0} {$x<10} {incr x} {
> puts "x is $x"
> }
> EOD
expect version 5.45.4
argv[0] = expect argv[1] = -d
set argc 0
set argv0 "expect"
set argv ""
executing commands from command file
missing operand at _@_
in expression "_@_<10"
(parsing expression "<10")
invoked from within
"for {set x 0} {<10} {incr x} {
puts "x is "
为什么这个例子的工作方式不同?
【问题讨论】:
-
$x在此处文档中展开。 -
在 shell 中嵌入 Expect 很棘手。看看我的sexpect (Expect for Shells),您可以用它来编写仅使用shell 代码的Expect 脚本。