expect "file name" {send "foo.bar\r"} #Name of file
expect "Overwrite?" {send "y\r"} #Yes, overwrite the file
Tcl (and hence expect) comments are a bit weird compared to other languages. A #
is only a comment if it appears as the first character of a word that shows up where a command would appear: see http://tcl.tk/man/tcl8.5/TclCmd/Tcl.htm , rule #10
So you want an explicit semicolon to terminate the command, and then a comment can follow
expect "file name" {send "foo.bar\r"} ; #Name of file
expect "Overwrite?" {send "y\r"} ; #Yes, overwrite the file
Here's why the error occurs: the expect
command takes a list of {pattern} {action}
pairs (or a single list containing "pattern action" pairs). The last pattern does not require an action. So with your misguided comments, expect saw the equivalent of this:
expect {
"file name" {send "foo.bar\r"}
"#Name" {of}
"file"
}
expect {
"Overwrite?" {send "y\r"}
"#Yes," {overwrite}
"the" {file}
}
There must have been a "the" that expect saw before "Overwrite?", so it dutifully tried to execute the action block: {file}
. The Tcl file
command requires a subcommand, did not get one, and expect threw the error.