Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add new line in bashrc file in ubuntu?

Tags:

bash

vim

ubuntu

I'm trying to update my bashrc file in ubuntu with some environment variables.

I can do this using below command.

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

But I want to do it manually, meaning open the file with vim editor then add it. The problem here is when I open the bashrc file the end line is "fi" and when I reach there and press insert and then enter to go to new line it stays at the same line and moves the fi word only or create A or C or B random characters.

May I know please some commands to handle this bashrc file so that I could add a new line and then my variables over there?

I've tried to look online but didn't find what am looking for.

like image 293
Squeez Avatar asked Mar 03 '18 11:03

Squeez


2 Answers

Since you didn't specify if you have terminal access only or also GUI. If you have terminal access only, any editor would do it. Popular editors like nano or vim come installed by default in most Ubuntu releases.

To use nano, in your terminal, type nano ~/.bashrc

Then press Ctrl + w +v to go to the end, add what you want to add, the Ctrl + o to save changes, Ctrl +x to exit. You will need to log out and log back on, or run source ~/.profile to make your changes available to your bash environment.

like image 139
R J Avatar answered Nov 08 '22 03:11

R J


Here's what you can do in vim.

  1. Press the letter G. It will take you to the last line.
  2. Press the letter O. It will allow you to insert text after the current lne.
  3. Type in your content - export APP=/opt/tinyos-2.x/apps
  4. Press the ESC key get out of editing mode.
  5. Press the key :. It will allow you type commands.
  6. Type wq followed by Enter. This will save the file and quit vim.

You are done.

like image 45
R Sahu Avatar answered Nov 08 '22 01:11

R Sahu