find/cygdrive/c/xampp/htdocs/news4u -type f -exec sed -i's/document.write(unescape(「%3Cscript src ='」+ gaJsHost +「google-analytics.com/ga.js 'type ='text/javascript'%3E%3C/script%3E「)); /(function(){var ga = document.createElement('script'); ga.type ='text/javascript'; ga。 async = true; ga.src =('https:'== document.location.protocol?'https:// ssl':'http:// www')+'.google-analytics.com/ga.js' ; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga,s);})();/g'{} \;如何逃避下面的序列,以便在shell腳本中使用sed替換文本?
這導致的誤差sed: -e expression #1, char 93: unknown option to
s'`
我使用Windows和使用 '的cygwin' 運行shell腳本。
如何解決這個問題,並應該單引號被轉義,因爲它再次被包含在單引號?
我用'find/cygdrive/c/xampp/htdocs/news4u/apps/frontend/modules/alerts/templates -type f -exec sed -i'/ document.write(unescape(「%3Cscript src =' 「+ gaJsHost +」google-analytics.com \ /ga.js'type ='text \/javascript'%3E%3C \/script%3E「)); /(function(){var ga = document.createElement( 'script'); ga.type ='text \/javascript'; ga.async = true; ga.src =('https:'== document.location.protocol?'https:\/\/ssl':' http:\/\/www')+'.google-analytics.com \ /ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga,s); })();/G {} \; ' – 2012-07-10 10:22:12
我逃脫了'/'而且它不起作用。還有什麼可以改變的? – 2012-07-10 10:23:17
你不僅必須''逃脫''而且'''也是。最好不要轉義'/',而是使用其他字符作爲's'的分隔符。 – 2012-07-10 10:59:03