Question

I'd like to create an expect script that connects to the server via telnet and does some authorisation. I have a problem with using script parameters though. Based on man I expected this to work:

#!/usr/bin/expect -f
spawn telnet $argv1 5038
...

Unfortunately I get back can't read "argv1": no such variable. How can make this work?

Was it helpful?

Solution

$argv is a Tcl list holding the command line parameters, indexed beginning from 0. You want:

[lindex $argv 0]

OTHER TIPS

Commmand line arguments are provided as a list in variable argv, you can use lindex to get an element from this list, so if the first argument is the host to telnet to, do:

spawn telnet [lindex $argv 0] 5038

See Shell Provided Variables in Shells and lindex in Lists

I got a similar error, can't read "argv0": no such variable, when I tried to use $argv0 in a proc. The solution was to explicitly access it from the global namespace by using $::argv0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top