Echoing aliases into a .bashrc file

2

I want to echo an alias straight into my .bashrc file. Here is what I am using:

echo alias cdear='cd | clear' >> .bashrc

However, the new line in .bashrc does not contain the quote marks.

I would also like this to go at the end of .bashrc with a line break from the last line.

How can I change my command in order to:

  1. ensure the quote marks are retained?
  2. ensure the alias is added to the end of the file with a line break?

user328721

Posted 2014-06-02T17:17:53.737

Reputation: 21

Answers

8

Surround the content of echo with double quotes. To get a newline before the new alias, use echo -e and insert a newline \n:

echo -e "\nalias cdear='cd | clear'" >> .bashrc

savanto

Posted 2014-06-02T17:17:53.737

Reputation: 419

That works flawlessly. I should have thought to contain the entire command in quotes that way. Thank you. – user328721 – 2014-06-02T20:18:44.247

@user328721: If an answer actually answers your question, you should mark it as accepted. – bjanssen – 2014-06-02T20:25:15.923