Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Shell脚本)如何将参数传递给预期脚本?_Shell_Expect - Fatal编程技术网

Shell脚本)如何将参数传递给预期脚本?

Shell脚本)如何将参数传递给预期脚本?,shell,expect,Shell,Expect,现在,我正在使用expect制作一个shell脚本,以向sftp服务器发送一个文件。 但是,当我将文件路径传递给shell脚本时,当使用“put”命令时,有一个空的文件路径参数。(也可以是get或put) 如何将参数传递给get或put命令 下面有一个代码 set FILEPATH [lindex $argv 0] expect << EOL sleep 3 spawn sftp id@sftp_ip expect "password:" send "mypassword\n" ex

现在,我正在使用expect制作一个shell脚本,以向sftp服务器发送一个文件。 但是,当我将文件路径传递给shell脚本时,当使用“put”命令时,有一个空的文件路径参数。(也可以是get或put)

如何将参数传递给get或put命令

下面有一个代码

set FILEPATH [lindex $argv 0]
expect << EOL
sleep 3
spawn sftp id@sftp_ip
expect "password:"
send "mypassword\n"
expect "sftp>"
send "cd /remote/directory\n"
expect "sftp>"
send "get $FILEPATH\n"
expect "sftp>"
send "exit\n"
interact

设置文件路径[lindex$argv 0]

expect
set FILEPATH[lindex$argv 0]
看起来像一个tcl命令,而不是shell命令,因此可能应该在expect脚本内部(需要使用适当的路径名作为参数运行)@sssrigo:Shawn是正确的。在expect代码之外编写Tcl命令有什么意义。但对于您的问题,将数据传递到Tcl/expect程序的另一种可能性是将其放置在环境中,然后可以通过
$env(VARNAME)
在Tcl内部检索这些数据。请看一下,您可以使用哪种方法仅使用shell代码编写expect脚本。