2017-03-17 148 views
0

我想替换以下字符串如何在linux中使用sed替换字符串中的单引号?

su - oracle -c "$agent_home/bin/emctl control agent runCollection ex01cel01:oracle_exadata oracle_exadata_configuration"

su - oracle -c "'$agent_home'/bin/emctl control agent runCollection ex01cel01 :oracle_exadata oracle_exadata_configuration"

注更换:额外的单引号覆盖$ agent_home

请帮我

+1

的【如何逃脱在sed单引号?](http://stackoverflow.com/questions/24509214/how-to-escape-single-quote-in-sed) – Sundeep

+0

哪里是可能的复制' sed(1)'呼吁这个问题?请不要滥用标签。 –

回答

1

以下sed命令应该执行

sed "s|\$agent_home|'\$agent_home'|" 
+1

或'sed's/$ agent_home/\ x27&\ x27 /''为了避免担心在双引号中逃脱shell解释 – Sundeep

+0

感谢彼得它工作 –