44

I need to add the following lines to the end of .bashrc file in Ubuntu. How can I add these lines automatically using a script. If I run the script, then it automatically inserts the lines at the end of .bashrc file.

export APP="/opt/tinyos-2.x/apps"
export TOS="/opt/tinyos-2.x/tos"
1
  • @deenaik post your edit as new question. Do not hijack existing, answered questions. – muru Apr 4 '17 at 10:31
77

Use the echo command to append lines to the .bashrc script

So in your script use these lines

echo 'export APP=/opt/tinyos-2.x/apps' >> ~/.bashrc 

echo  'export TOS=/opt/tinyos-2.x/tos' >> ~/.bashrc 

Make sure to use >> (append), if you use a single > you will overwrite the file.

~/.bashrc indicates .bashrc is in your home directory

2
  • When I do this it appends the echoed string to the last line already in the bashrc file; as in, not on a new line and without a space on the current last line... – d8aninja Sep 17 '18 at 17:16
  • 1
    @d8aninja, this would happen if the last line of your file was not terminated with EOL character (0x0A). – Alexey Nov 7 '18 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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