Shell – Echoing something with multiple quotes and key characters (&, $, !, etc.)

echoquotingshell-script

Let's say you have to echo this into a file:

RZW"a4k6[)b!^"%*X6Evf

How do you do it?

My actual "line" to echo is a 2048 characters line.

Best Answer

Just put it in single quotes:

echo 'RZW"a4k6[)b!^"%*X6Evf' > file

But if you have any single quotes in the string you need to escape each of those in double quotes ("'") and "glue" the result together like this:

echo 'text without single quotes'"'"'and other text without single quote'