eDeviser
eDeviser

Reputation: 1863

How to do some calculation in expect script?

What I need to do is to set a variable at the beginning of an expect script to a value which depends on th size of a file. What I need to do is something like this:

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

I already searched around for some tutorials, but searching the keywords 'expect' and 'calculation' are too common, so the search results do not face the unix binary /usr/bin/expect.

How to do some calculation in expect script?

Upvotes: 0

Views: 585

Answers (2)

glenn jackman
glenn jackman

Reputation: 246774

No need to call out to stat:

set filesize [file size foo.bin]

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

Upvotes: 2

pynexj
pynexj

Reputation: 20688

Expect uses Tcl so you also need to learn Tcl's manual.

To quickly help you out:

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

Upvotes: 1

Related Questions