Ubuntu – How to escape `$` and `#` symbols in bash


I have a simple string I want to echo from my bash script:

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

But any how I try to add \ before # I cant echo it=( So I wonder – how to echo such command?

Best Answer

Because you already have single quotes in the string, use double quotes, and escape only the $ sign:

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