Well. Thanks for all your kindly help. I have learn from your that, to use a variable in sed we have to use ” ” instead of ‘ ‘. However, in my case , before i use ‘ ‘ and without variable, it works well. After using ” ” and variable ($title, $web, $desc) it doesn’t functioning anymore, what is the reason?? thanks.
Before
sed -i '0,/<item pop="N">/ { s/<item pop="N">/<item pop="N">\n <title>test1<\/title>\n <guid>test2<\/guid>\n <link>test3<\/link>\n <description><![CDATA[<p>test4<\/p>]]><\/description>\n <\/item>\n<item pop="N">/ }' /var/www/html/INFOSEC/english/rss/test.xml
After
sed -i "0,/<item pop="N">/ { s/<item pop="N">/<item pop="N">\n <title>News: $title<\/title>\n <guid>$web<\/guid>\n <link>$web<\/link>\n <description><![CDATA[<p>$desc<\/p>]]><\/description>\n <\/item>\n<item pop="N">/ }" /var/www/html/INFOSEC/english/rss/test.xml
I have run it separately instead of the whole script
it turn out the error -bash: ![CDATA[: event not found, actually i should not run it alone as i need to input something in the variable
You are using
"inside the string. These characters need to be escaped.Also, it’s likely that your shell escapes the
\characters inside"", and not inside''. You have at least two solutions:Either keep everything inside
""but replace\with\\, and"s with\":Or mix the two; when you need to insert a variable, exit
', enter your variable inside"", and re-enter':