我在 ubuntu 15.04 上,我的 ssh 客户端版本是
OpenSSH_6.9p1 Ubuntu-2ubuntu0.2, OpenSSL 1.0.2d 9 Jul 2015
当我尝试运行以下命令时ssh admin@server bash -c 'cd /path/to/repo && git pull'
CD 无效,我得到了
fatal: Not a git repository (or any of the parent directories): .git
但是如果我这样做
ssh admin@server bash -c 'echo test && cd /path/to/repo && git pull'
然后就可以了
Already up-to-date.
我当然很清楚echo
不应该改变任何东西,但在几个不同的服务器上尝试了几次、几天后(尽管都在 debian 上),我现在肯定会遇到这个错误。
在其他服务器上我尝试了该命令cd /tmp && pwd
,我得到了我的主目录,如果我这样做了echo toto && /tmp && pwd
I go /tmp
打印...
不幸的是,ssh 通过单个命令行字符串来$SHELL -c
在遥控器上。你的报价没有效果。
当你跑步时
ssh admin@server bash -c 'cd /path/to/repo && git pull'
这正在远程服务器上运行($SHELL -c
):
bash -c cd /path/to/repo && git pull
所以 Bash 被给予单个命令(cd
)和一个未使用的参数,然后单独运行git pull
在主目录中。
另一方面,当你跑步时
ssh admin@server bash -c 'echo test && cd /path/to/repo && git pull'
这是在远程服务器上运行的:
bash -c echo test && cd /path/to/repo && git pull
第一部分再次无用,但运行整个命令的 shell 会执行此操作cd /path/to/repo
and git pull
。这有效。
你可能想做的是
ssh admin@server 'cd /path/to/repo && git pull'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)