如何在脚本之间传输控制?

问题描述:

#!/usr/bin/expect -f 
spawn telnet 10.123.9.111 
expect login {send username\r} 
expect password {send password\r} 
----Here i want to execute commands---- 
----Commands are stored in an array in example.pl script---- 
----All variables are global in perl script---- 
----After executing these commands, control should again transfer to the called perl script---- 

我该如何做到?这是正确的方式吗?或者有更好的方法来做到这一点?如何在脚本之间传输控制?

您需要从Perl驱动控制。我会从Perl动态编写期望脚本,编码命令以从数组运行。然后Perl可以执行期望脚本:

system "expect", "/tmp/newly_written_script.exp"; 

并在期望返回时继续进程。