简体   繁体   English

如何在ubuntu中的bashrc文件中添加新行?

[英]How to add new line in bashrc file in ubuntu?

I'm trying to update my bashrc file in ubuntu with some environment variables. 我正在尝试使用一些环境变量更新ubuntu中的bashrc文件。

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. 但我想手动完成,这意味着用vim编辑器打开文件然后添加它。 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. 这里的问题是,当我打开bashrc文件时,结束行是“fi”,当我到达那里并按下插入然后输入转到新行它停留在同一行并仅移动fi字或创建A或C或B随机字符。

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? 我可以知道一些命令来处理这个bashrc文件,以便我可以在那里添加一个新行然后我的变量吗?

I've tried to look online but didn't find what am looking for. 我试图在网上看,但没找到我在找什么。

Since you didn't specify if you have terminal access only or also GUI. 由于您未指定是仅具有终端访问权限还是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. 大多数Ubuntu版本默认安装了nanovim等热门编辑器。

To use nano, in your terminal, type nano ~/.bashrc 要在终端中使用nano,请键入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. 然后按Ctrl + w + v转到结尾,添加要添加的内容,按Ctrl + o保存更改,按Ctrl + x退出。 You will need to log out and log back on, or run source ~/.profile to make your changes available to your bash environment. 您需要注销并重新登录,或运行source ~/.profile以使您的更改可用于您的bash环境。

Here's what you can do in vim. 这是你在vim中可以做的。

  1. Press the letter G . 按字母G It will take you to the last line. 它会带你到最后一行。
  2. Press the letter O . 按字母O It will allow you to insert text after the current lne. 它允许您在当前lne之后插入文本。
  3. Type in your content - export APP=/opt/tinyos-2.x/apps 输入您的内容 - export APP=/opt/tinyos-2.x/apps
  4. Press the ESC key get out of editing mode. ESC键退出编辑模式。
  5. Press the key : . 按键: It will allow you type commands. 它将允许您键入命令。
  6. Type wq followed by Enter . 键入wq然后按Enter键 This will save the file and quit vim. 这将保存文件并退出vim。

You are done. 你完成了。

As you are using Vim / Vi editor you need to use i/insert key to start editing, then for saving use escape & then wq to save and exit. 当您使用Vim / Vi编辑器时,您需要使用i / insert键开始编辑,然后使用保存使用转义然后使用wq保存并退出。 For More detailed instructions please visit this link 有关更详细的说明,请访问此链接

Honestly, learning vim in a week (or even in a day) is tough. 老实说,在一周(甚至一天)学习vim很难。 Took me more than a month to actually be productive on it as mh daily editor. 花了一个多月的时间才真正高效地做每日编辑。 But just to tell you. 但只是告诉你。 Go to the line after which you want to ass a new line using HJKL or arrow keys. 使用HJKL或箭头键转到要在其后面添加新行的行。 Then presss o . 然后按o It'll spawn a new line below it and go into insert mode as well. 它会在它下面生成一个新行并进入插入模式。 Then write and press Esc . 然后写下并按Esc Enter :wq . 输入:wq

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM