简体   繁体   English

sed命令不显示双引号

[英]Sed command not showing double quotes

I am using "sed" command to replace a string from a ".properties" file in linux shell script. 我在Linux Shell脚本中使用“ sed”命令替换“ .properties”文件中的字符串。 The problem is that it is not showing the double quotes. 问题在于它没有显示双引号。

Note: I think sed command ignores the double quotes,so is there anyway to explicitly force it to not ignore it. 注意:我认为sed命令会忽略双引号,因此无论如何有明确地强制它不要忽略它。

"Shell Script File" “ Shell脚本文件”

#!/bin/bash

# First Script
#Include Properties File
. directoryPaths.properties

sed -i "s#EPOLD#$EPNEW#" *Test*

Properties File: 属性文件:

EPNEW="jms:/Queue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue format="pox" "

File: 文件:

<?xml version="1.0" encoding="UTF-8"?>
    <endpoint xmlns="http://ws.apache.org/ns/synapse" name="Component">
        <address uri=EPOLD/>
    </endpoint>

Current Result: 当前结果:

<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="Component">
    <address uri=jms:/Queue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactoryGLBookingService_EPLOCALamp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactoryGLBookingService_EPLOCALamp;java.naming.provider.url=tcp://localhost:61616GLBookingService_EPLOCALamp;transport.jms.DestinationType=queue format=pox />
</endpoint>

Expected Result: 预期结果:

<?xml version="1.0" encoding="UTF-8"?>
    <endpoint xmlns="http://ws.apache.org/ns/synapse" name="Component">
        <address uri="jms:/Queue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactoryGLBookingService_EPLOCALamp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactoryGLBookingService_EPLOCALamp;java.naming.provider.url=tcp://localhost:61616GLBookingService_EPLOCALamp;transport.jms.DestinationType=queue format="pox" " />
    </endpoint>

Assign your variable by inserting literal double quotes: 通过插入文字双引号来分配变量:

EPNEW='"jms:/Queue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616&amp;transport.jms.DestinationType=queue format="pox" "'

Your assignment is this: 您的任务是这样的:

EPNEW="jms:/Queue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616&amp;transport.jms.DestinationType=queue format="pox" "

Which will leave this value in EPNEW : 它将在EPNEW保留此值:

jms:/Queue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616&amp;transport.jms.DestinationType=queue format=pox

Try with quotes in sed: 尝试使用sed中的引号:

sed -i "s#EPOLD#\"$EPNEW\"#" *Test*

Your quotes is getting missed when you source your properties file and not ignored by sed. 当您获取属性文件并且未被sed忽略时,引号会丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM