views:

139

answers:

2

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?

+3  A: 

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

[lindex $argv 0]
glenn jackman
You won by 2 minutes :) Thanks. There's an example in man that mentions $argv0, which is what confused me.
viraptor
+5  A: 

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

Colin Macleod