【发布时间】:2014-08-26 17:42:58
【问题描述】:
我有一个通过 SSH 连接到测试服务器并检索当前 Git 分支的脚本。当我尝试使用变量打印分支和修改文件的数量时,我用转义符号堆叠。
以下内容适用于本地文件夹:
mc=$(git status -s | grep -E '^[^?]+' -c);
branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/');
echo $branch \($mc\)
但这行不通:
ssh -i ~/.ssh/id_rsa.cron local.stage "cd /var/www && mc=$(git status -s | grep -E '^[^?]+' -c);
branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/');
echo $branch \($mc\)"
【问题讨论】:
-
1) 使用heredoc 而不是将所有指令放在第一行 2)
it won't work是什么意思?一般来说,当您使用 ssh 转义某些内容时,这意味着它将在您的远程计算机上进行解释。否则,将在本地解释。你的问题可能就在这里。