Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何将变量从shell脚本传递到expect脚本?_Bash_Shell_Expect - Fatal编程技术网

Bash 如何将变量从shell脚本传递到expect脚本?

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

我的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" ;;
    *) 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