为什么每次打开终端以使别名正常工作时都必须提供.bashrc? [英] Why must I source .bashrc every time I open terminal for aliases to work?

查看:78
本文介绍了为什么每次打开终端以使别名正常工作时都必须提供.bashrc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git运行正常.我已经在Git中创建了一个别名,但是问题是当我尝试重新打开终端时,我需要运行.每次在终端中都〜/.bashrc .

Git was working fine. I have created an alias in Git but the issue is when I tried to reopen the terminal, then I need to run . ~/.bashrc every time in the terminal.

重新打开终端时,每次不需要提供源的最佳方法是什么?

What is the best way I don't need to provide source every time when I reopen the terminal?

我做了什么?我正在尝试在此文件中添加 .bashrc 文件的 source ,但这是一个只读文件.我无法在此配置文件中添加 .bashrc 文件的 source .

What I did? I am trying to add source of the .bashrc file in this file but it is a read-only file. I am not able to add the source of the .bashrc file in this profile.

open /etc/profile

还添加了在配置文件中写入的权限,但仍然无法链接源文件.

Added the permission to write in the profile as well, still not able to link the source file.

sudo chmod u+w /etc/profile

个人资料:

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
   eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
   [ -r /etc/bashrc ] && . /etc/bashrc
fi

推荐答案

您的终端模拟器似乎正在启动 bash 作为登录shell.

It looks like your terminal emulator is launching bash as a login shell.

在这种情况下,它将读取/etc/profile 进行配置以及以下文件的 1个(如果存在)(按重要性顺序列出):

If that's the case, it will read /etc/profile for configuration as well as 1 of the following files, if they exist (listed in order of importance) :

  • 〜/.bash_profile
  • 〜/.bash_login
  • 〜/.profile

因此它将忽略您的 .bashrc 文件.针对您的情况的正确解决方案是将终端仿真器配置为以交互方式运行bash且不登录,或者添加 [-f"$ HOME/.bashrc"]&&源"$ HOME/.bashrc" 到您的〜/.bash_profile

It will thus ignore your .bashrc file. A correct fix for your situation would be to either configure your terminal emulator to run bash interactively and non-login, or add [ -f "$HOME/.bashrc" ] && source "$HOME/.bashrc" to your ~/.bash_profile

此处是指向有关要加载的文件的文档,具体取决于您所运行的Shell的类型

Here is a link to the documentation about which files are loaded depending of the type of shell you are running

这篇关于为什么每次打开终端以使别名正常工作时都必须提供.bashrc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆