Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

a) ensure the quote marks are retained?
b) ensure the alias is added to the end of the file with a line break?

share|improve this question

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
share|improve this answer
That works flawlessly. I should have thought to contain the entire command in quotes that way. Thank you. – user328721 Jun 2 '14 at 20:18
@user328721: If an answer actually answers your question, you should mark it as accepted. – bjanssen Jun 2 '14 at 20:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.