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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49083789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:51:03  来源:igfitidea点击:

How to add new line in bashrc file in ubuntu?

bashubuntuvim

提问by Squeez

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. 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.

但我想手动完成,这意味着用 vim 编辑器打开文件然后添加它。这里的问题是,当我打开 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.

我试过在网上看,但没有找到我要找的东西。

回答by R J

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 nanoor vimcome installed by default in most Ubuntu releases.

由于您没有指定您是否只有终端访问权限或 GUI。如果您只有终端访问权限,任何编辑器都会这样做。在大多数 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. You will need to log out and log back on, or run source ~/.profileto make your changes available to your bash environment.

然后按 Ctrl + w +v 到最后,添加要添加的内容, Ctrl + o 保存更改, Ctrl +x 退出。您将需要注销并重新登录,或运行source ~/.profile以使您的更改可用于您的 bash 环境。

回答by R Sahu

Here's what you can do in vim.

这是您可以在 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 ESCkey get out of editing mode.
  5. Press the key :. It will allow you type commands.
  6. Type wqfollowed by Enter. This will save the file and quit vim.
  1. 按字母G。它会带你到最后一行。
  2. 按字母O。它将允许您在当前 lne 之后插入文本。
  3. 输入您的内容 - export APP=/opt/tinyos-2.x/apps
  4. ESC键退出编辑模式。
  5. 按 键:。它将允许您键入命令。
  6. 键入wq后跟Enter. 这将保存文件并退出 vim。

You are done.

你完成了。

回答by Vaibhav Dhoke

As you are using Vim/Vieditor you need to use i/insert key to start editing, then for saving use escape & then wq to save and exit. For More detailed instructions please visit this link

当您使用Vim/ Vieditor 时,您需要使用 i/insert 键开始编辑,然后使用 escape & 然后 wq 保存并退出。有关更详细的说明,请访问此链接

回答by GLaDOS

Honestly, learning vim in a week (or even in a day) is tough. 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 H-J-K-Lor arrow keys. Then presss o. It'll spawn a new line below it and go into insert mode as well. Then write and press Esc. Enter :wq.

老实说,一周(甚至一天)学习 vim 是很困难的。作为 mh 每日编辑,我花了一个多月的时间才真正提高了效率。但只是想告诉你。使用H-J-K-L或 箭头键转到要在其后添加新行的行。然后按o。它会在它下面生成一个新行并进入插入模式。然后写入并按Esc。输入:wq