Escape every character in bash I want to take a string like this:

Example string 59^!#&amp;$(


And turn it into this:

\E\x\a\m\p\l\e\ \s\t\r\i\n\g\ \5\9\^\!\#\&amp;\$\(


I've tried:

sed -e 's/./\\&amp;/g; 1{$s/^$/""/}; 1!s/^/"/; $!s/$/"/'

as noted here:


https://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-when-using-bash/20053121#20053121


But as noted by dalelane in a comment, this does not work under vanilla installation of bash in macOS. I have confirmed this with macOS High Sierra.

Any suggestions?
This works for me with bsd sed-

echo "I am a jelly donut" | sed 's/./\\&amp;/g'
\I\ \a\m\ \a\ \j\e\l\l\y\ \d\o\n\u\t


and with your string

echo 'Example string 59^!#&amp;$(' | sed 's/./\\&amp;/g'
\E\x\a\m\p\l\e\ \s\t\r\i\n\g\ \5\9\^\!\#\&amp;\$\(