我在脚本格式中使用sftp相对较新(在Mac OSX High Sierra上使用bash shell)。登录到远程服务器后,我在更改目录时遇到问题。我想cd到'FTP PDF(下载)到CR'这是我的脚本(已编辑):
#!/bin/bash
expect -c "
spawn sftp [email protected]
expect \"Password\"
send \"xxxxxxx\r\"
expect \"sftp>\"
send \"cd CR\ Reports\r\"
#DIR TO CD to "CR REPORTS"
expect \"sftp>\"
send \"bye\r\"
expect \"#\"
"
这实际上只是一个格式化的评论,扩展了@meuh的评论。
你有引用麻烦。您可以使用单引号或引用的heredoc来让您的生活更轻松
#!/bin/bash
expect <<'END_EXPECT'
spawn sftp [email protected]
expect "Password"
send "xxxxxxx\r"
expect "sftp>"
send "cd 'CR Reports'\r"
#DIR TO CD to "CR REPORTS"
expect "sftp>"
send "bye\r"
expect "#"
END_EXPECT
或者,只是一个期望脚本:
#!/usr/bin/expect -f
spawn sftp [email protected]
expect "Password"
send "xxxxxxx\r"
expect "sftp>"
send "cd 'CR Reports'\r"
#DIR TO CD to "CR REPORTS"
expect "sftp>"
send "bye\r"
expect "#"