如何在bash中转义`$`和`#`符号?


14

我有一个想从bash脚本中回显的简单字符串:

$(document).ready(function() {$('#cf-footer-paragraph').append('<p>Revision 12345</p>');});

但是任何我尝试\在#之前添加的内容我都无法回显它=(所以我想知道-如何回显这样的命令?


1
使用双引号“,而不是试图单和\‘......当然,你仍然需要逃避任何$,?’
亚光

Answers:


20

因为字符串中已经有单引号,所以请使用双引号,并仅转义$符号:

echo "\$(document).ready(function() {\$('#cf-footer-paragraph').append('<p>Revision 12345</p>');});"
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.