linux - Escape double quote inside a single quote -
for x in $(cat raw_tables.txt) echo '{ "type" : "jdbc", "jdbc" : { "url" : "jdbc:mysql://localhost:3306/test", "user" : "root", "password" : "<pass>", "sql" : "select * "'$x'"", "elasticsearch" { "cluster" : "search", "host": "<ip>", "port": 9300 }, "index" : ""'$x'"", "type": ""'$x'"" } }' | java \ -cp "/etc/elasticsearch/elasticsearch-jdbc-2.3.3.1/lib/*" \ -dlog4j.configurationfile=/etc/elasticsearch/elasticsearch-jdbc-2.3.3.1/bin/log4j2.xml \ org.xbib.tools.runner \ org.xbib.tools.jdbcimporter cat raw_tables.txt table1 table2 table3
when run comes out
"index" : ""$x"",
i need come out "index" : "$x", can't bypass double quote it's producing , if try escaping entire thing single quote script thinks it's stopped.
i've tried everything.. appreciated
thank you!
use here-document, way don't have care quoting (in case, since document doesn't need contain backticks or dollar signs):
while read x; java ... lots of options \ more options java \ , more options java <<end_doc { "type" : "jdbc", "jdbc" : { "url" : "jdbc:mysql://localhost:3306/test", "user" : "root", "password" : "<pass>", "sql" : "select * $x", "elasticsearch" { "cluster" : "search", "host": "<ip>", "port": 9300 }, "index" : "$x", "type": "$x" } } end_doc done <raw_tables.txt
the end marker (end_doc
in case) needs flush left, no indentation.
Comments
Post a Comment