Article 53PH1 add literal string with simple and double quotes to a file

add literal string with simple and double quotes to a file

by
vincix
from LinuxQuestions.org on (#53PH1)
I'm trying to add the following string to a file:
Code:sed 's|\$MYSQL_PASSWORD|'"$MYSQL_PASSWORD"'|'I'm using the simple and double quote syntax so that sed would use the MYSQL_PASSWORD variable (in the second part; the first part is literally $MYSQL_PASSWORD) when sed is run in the file I'm trying to add the line to.

What I've tried to far is:
Code:echo sed 's|\$MYSQL_PASSWORD|'"\$MYSQL_PASSWORD"'|' > fileBut unfortunately it drops the quote altogether:
Code:sed s|\$MYSQL_PASSWORD|$MYSQL_PASSWORD|Somewhat closer is:
Code:echo sed 's|\$MYSQL_PASSWORD|'"'"\$MYSQL_PASSWORD"'"'|'But this drops the double quotes:
Code:sed s|\$MYSQL_PASSWORD|'$MYSQL_PASSWORD'|This is becoming a little bit retarded, so if there are more elegant solutions, I'm looking forward to it :)

Ok, I was actually able to find a horrible solution:
Code:echo sed \''s|\$MYSQL_PASSWORD|'"'\""\$MYSQL_PASSWORD"'"\"'|'\'But the question remains: is there any other way to achieve this?
Thanks!latest?d=yIl2AUoC8zA latest?i=a6qDcK1GvyQ:K9l8IWsiE1A:F7zBnMy latest?i=a6qDcK1GvyQ:K9l8IWsiE1A:V_sGLiP latest?d=qj6IDK7rITs latest?i=a6qDcK1GvyQ:K9l8IWsiE1A:gIN9vFwa6qDcK1GvyQ
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments