How to echo line with multiple quotes/special characters into file?

Viewed 13095

I am trying to echo the following line into a .profile but it keeps getting confused by either the many quotes or special characters.

bind '"e[A": history-search-backward'

I've tried all sorts of things but can't get it nailed.

This is what I currently have:

sudo su -c 'echo "bind \'\"\\e[A\": history-search-backward\'" >> /etc/profile' -

This is what it returns:

su: user '"\e[A": does not exist

Yet if I just use:

echo bind \'\"\\e[A\": history-search-backward\'" >> /home/user/testfile

It works just fine.

I have all manner of "sudo su -c "echo blah..." in the rest of my script that work just fine.

Any ideas?

2 Answers
Related