从 Windows cmd 在 bash 中调用 rsync

Calling rsync in bash from Windows cmd

我正在尝试从批处理文件中 运行 rsync。命令是

SET CMD="rsync -P -rptz --delete -e 'ssh -i /root/.ssh/CERTIFICATE.pem' SOURCE_ADDRESS  /mnt/c/Users/MYNAME/IdeaProjects/PROJECT/SUBFOLDER/SUBFOLDER/SUBFOLDER/SUBFOLDER/LASTFOLDER"

bash %CMD%

如果我在输入 bash 后 运行 命令,这工作正常,但是当我 运行 来自带有 bash 前体的 cmd 命令时,它说没有这样的文件或目录。

此外,当尝试调试 bash 时挂起...即如果我打开 bash 我没有得到任何提示,只有一个闪烁的光标。

感谢任何帮助。

要运行一个带有bash的命令你需要使用-c option

bash -c "%CMD%"

如果没有它,第一个 non-option 参数将被视为 *.sh shell 脚本,而 rsync 不是并且会导致错误

If arguments remain after option processing, and neither the -c nor the -s option has been supplied, the first argument is assumed to be the name of a file containing shell commands.

请注意,Windows 中的 cmd 不是 DOS,尽管它们有一些类似的命令。其余的大不相同