如何在期望脚本中进行一些计算?

How to do some calculation in expect script?

我需要做的是在 expect 脚本的开头将一个变量设置为一个取决于文件大小的值。我需要做的是这样的:

set filesize `stat -c%s foo.bin`
set factor 42
set timeout $filesize / $factor

我已经四处搜索了一些教程,但是搜索关键字'expect'和'calculation'太常见了,所以搜索结果没有面向unix二进制文件/usr/bin/expect。

如何在 expect 脚本中进行一些计算?

Expect 使用 Tcl,因此您还需要学习 Tcl's manual

快速帮您解决:

set filesize [exec stat -c%s foo.bin]
set factor 42
set timeout [expr {$filesize / $factor}]

无需呼叫stat:

set filesize [file size foo.bin]

https://tcl.tk/man/tcl8.6/TclCmd/file.htm#M34