使用SSH时转义引号 [英] Escaping quotes when using SSH
问题描述
我正在为我的PHP应用程序构建一个简单的部署脚本。我知道这个工作有几个工具(Capistrano,Phing等),但是对于我简单的部署例程,他们似乎是很多工作。
I'm trying to build a simple deployment script for my PHP apps. I know there are several tools for this job (Capistrano, Phing, etc.) but they seem like a lot of work for my simple deployment routine.
我使用 sshpass ,以避免重复键入我的密码。但上传压缩安装程序后,我需要ssh进入服务器并运行一些命令。其中一个是sed。所以,引号打破了我的脚本。这是这样的:
I use sshpass to avoid typing my password over and over again. But after uploading my compressed installer, I need to ssh into the server and run some commands. One of which is sed. So, quotes are breaking my script. It's something like this:
sshpass -p foo ssh user@host "
cd /www/htdocs/foo/bar
echo 'Untar and remove installer'
tar -zxf install.tar.gz
sed "s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');" index.php > tmp && mv tmp index.php
sed "s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');/" admin/index.php > tmp && mv tmp admin/index.php
"
当你可以看到,我使用双引号启动我的SSH语句,但是我也需要在sed上使用它们。
As you can see, I use double-quotes to start my SSH statements, but I also need to use them on sed.
任何建议将不胜感激。谢谢!
Any suggestions would be greatly appreciated. Thanks!
推荐答案
转义内部引号是正常的方式。这不行吗?
Escaping the internal quote marks is the normal way. Does this not work?
sshpass -p foo ssh user@host "
cd /www/htdocs/foo/bar
echo 'Untar and remove installer'
tar -zxf install.tar.gz
sed \"s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');\" index.php > tmp && mv tmp index.php
sed \"s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');/\" admin/index.php > tmp && mv tmp admin/index.php
"
这篇关于使用SSH时转义引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!