sftp - 具有 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
)
解决方案
因为heredoc 没有被引用,所以shell 在启动expect 之前扩展了变量。用途$HOME
:波浪号在 Tcl/expect 中没有特殊意义。
推荐阅读
- oracle - 如何为 Oracle 优化 Dockerfile?
- xilinx-ise - 如何为 Ubuntu 19.10 安装 Xilinx ISE 14.7
- java - Java查找不包含在对象列表中的对象
- windows - 理解 SYSTEM_POWER_INFORMATION 结构中的 MaxIdlenessAllowed 和 TimeRemaining
- c++ - 交换字符串(字符串下标超出范围错误)
- c - 文件锁定程序不锁定文件
- python - Python中的字符串插值已经包含大括号
- excel - excel VBA中的循环列引用以更改另一个工作表
- ruby - 字符串操作挑战
- javascript - 如何使用 webpack 从模板加载 VueJS 应用程序?