【发布时间】:2021-11-09 01:30:10
【问题描述】:
我正在尝试将 bash 脚本中的 cd 命令运行到 SFTP 会话。我的代码目前看起来像
#!/bin/bash
sftp $1@$2
然后我想在 SFTP 会话和其他命令中使用cd,但现在 cd 没问题。我该怎么做?
【问题讨论】:
我正在尝试将 bash 脚本中的 cd 命令运行到 SFTP 会话。我的代码目前看起来像
#!/bin/bash
sftp $1@$2
然后我想在 SFTP 会话和其他命令中使用cd,但现在 cd 没问题。我该怎么做?
【问题讨论】:
尝试批处理模式。引用手册页:
-b batchfile
Batch mode reads a series of commands from an input
batchfile instead of stdin. [...] A batchfile of ‘-’ may be used to indicate standard input.
您可以使用批处理模式按顺序运行命令,例如
#!/bin/bash
echo << EOF > sftp-commands-to-run.txt
ls
put myfile.txt
... more commands ...
EOF
sftp -b sftp-commands-to-run.txt $1@$2
你也可以通过stdin传递命令来运行,例如
#!/bin/bash
echo ls myfile.txt | sftp -b - $1@$2
【讨论】: