Bash 如何将变量从shell脚本传递到expect脚本?
我的shell脚本如下所示:Bash 如何将变量从shell脚本传递到expect脚本?,bash,shell,expect,Bash,Shell,Expect,我的shell脚本如下所示: #!/bin/bash echo "Select the Gateway Server:" echo " 1. Gateway 1" echo " 2. Gateway 2" echo " 3. Gateway 3" read gatewayHost case $gatewayHost in 1) gateway="abc.com" ;; 2) gateway="pqr.com" ;; 3) gateway="xyz.com
#!/bin/bash
echo "Select the Gateway Server:"
echo " 1. Gateway 1"
echo " 2. Gateway 2"
echo " 3. Gateway 3"
read gatewayHost
case $gatewayHost in
1) gateway="abc.com" ;;
2) gateway="pqr.com" ;;
3) gateway="xyz.com" ;;
*) echo "Invalid choice" ;;
esac
/mypath/abc
在上面的脚本中,我从用户输入选择中获取网关并尝试传递到我的abc.sh脚本,该脚本如下所示:
#!/usr/bin/expect
set timeout 3
spawn ssh "james@$gateway"
expect "password:"
send "TSfdsHhtfs\r";
interact
但我无法将shell脚本中的网关变量传递给expect脚本。有人能告诉我如何做到这一点吗??请注意,我只需要使用shell脚本,这是由于遗留原因(无法使用tcl脚本或无法在expect脚本本身中完成所有操作)来自您的shell脚本:
/mypath/abc $gateway
从expect脚本:
#!/usr/bin/expect
set gateway [lindex $argv 0]; # Grab the first command line parameter
set timeout 3
spawn ssh "james@$gateway"
expect "password:"
send "TSfdsHhtfs\r";
interact