Re: passing a variable to an expect script



scriptnewbe wrote:
I have a ksh script that does some calculations on the dates and then
passed 3 dates to an expect script.

Ksh script variable:
/dir1/dir2/Scripts/achcust $yd1 $yd2 $yd3

Then in my expect script, I have
set yd1 "[lrange $argv 0 0]"
set yd2 "[lrange $argv 1 1]"
set yd3 "[lrange $argv 2 2]"


Later in the script when I am trying to use the set string ....., I try
to call the variable $yd1 $yd2 and $yd3.

The expect script is not recognizing the variables. The odd thing is
that when I run a ps -ef |grep on the script while it is running, it
has the correct values being passed to the expect script.

Help me please!


The short answer is: you're doing something wrong, but without seeing your code it is impossible to know what mistake you've made.

If I had to guess (and I guess I do...) I'd say that either you're doing the "set yd1 ..." in a proc and haven't declared argv as global, or the place where you're using yd1, etc doesn't declare those variables as global.

Do either of those sound like the problem?

Also, [lrange $argv 0 0] is incorrect and could yield bad results. You should use [lindex $argv 0]. lrange returns a list, lindex does not.

Most of the time it won't matter, but if any of the arguments have special characters you'll discover that [lrange $argv 0 0] is not precisely the same as [lindex $argv 0] (and the latter will return the proper value).


--
Bryan Oakley
http://www.tclscripting.com
.



Relevant Pages

  • Help with expect
    ... having an issue with this particular script that I just cannot seem to ... set user [lindex $argv 0] ... timeout ...
    (comp.lang.tcl)
  • expect script to ssh to server, login as root, run commands
    ... I'm using the expect script below to be called from a ksh script and ... commands being run as root succeed or not, but wasn't sure how to trap ... set SERVER [lindex $argv 0] ...
    (comp.lang.tcl)
  • Help with expect script
    ... I have an expect script that logs into a host and updates some OS ... I have the telnet portion ... set Receiver [lindex $argv 0]; ...
    (comp.lang.tcl)
  • Help with expect script
    ... I have an expect script that logs into a host and updates some OS ... I have the telnet portion ... set Receiver [lindex $argv 0]; ...
    (comp.unix.shell)
  • Re: freewrap exec help!!
    ... via [lindex $args 0] mechanism. ... thanks for helping ...
    (comp.lang.tcl)