首页 > 解决方案 > 具有 Expect 语法的 SFTP BSD Zsh 批处理文件

问题描述

我在 MacOS 中有一个 zsh 脚本——试图自动化 -b(批处理文件选项),但“~”似乎没有在期望语法中扩展。Expect 无法在该目录中找到批处理文件位置,即使它在那里。我需要完整路径还是像 $HOME 这样的全局变量不能在预期范围内工作?

deletedfiles=$(/usr/bin/expect <<SFTP
    set timeout -1
    spawn /usr/bin/sftp -b ~/Desktop/pgmfilesremoved.txt Port=${port} ${sftpuser}@${host}
    expect "Password authentication"
    expect "Password:"
    send "${password}\r"
    expect "sftp>"
    send "exit\r"
    SFTP
    )

标签: sftpzshexpectbsd

解决方案


因为heredoc 没有被引用,所以shell 在启动expect 之前扩展了变量。用途$HOME:波浪号在 Tcl/expect 中没有特殊意义。


推荐阅读