主目录中的.bashrc是否应自动加载?

And*_*ndy 5 macos bash

我在我的.bashrc文件中添加了scala,但是当我关闭我的mac并将其重新打开时它没有找到它.当我做

source ~/.bashrc 
Run Code Online (Sandbox Code Playgroud)

一切都恢复正常了.我会说问题一般是整个文件,但问题是,我还有其他的东西在之前工作得很好,但问题是scala持续存在.有谁知道这是为什么并解释我为什么会遇到这个问题?这是我的.bashrc文件中的内容,它正确运行rvm和mysql,但不是scala:

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
export PATH="/usr/local/mysql/bin:$PATH"
export PATH="/Users/Zeroe/scala-2.9.1-1/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)

kev*_*kev 38

我通过添加echo "${BASH_SOURCE[0]}"到这些脚本来弄清楚这个图.

                     +-----------------+   +------FIRST-------+   +-----------------+
                     |                 |   | ~/.bash_profile  |   |                 |
login shell -------->|  /etc/profile   |-->| ~/.bash_login ------>|  ~/.bashrc      |
                     |                 |   | ~/.profile       |   |                 |
                     +-----------------+   +------------------+   +-----------------+
                     +-----------------+   +-----------------+
                     |                 |   |                 |
interactive shell -->|  ~/.bashrc -------->| /etc/bashrc     |
                     |                 |   |                 |
                     +-----------------+   +-----------------+
                     +-----------------+
                     |                 |
logout shell ------->|  ~/.bash_logout |
                     |                 |
                     +-----------------+
Run Code Online (Sandbox Code Playgroud)

注意

  1. []-->[]意思是source by workflow(自动).
  2. [--->[]意思是source by convention(手工.如果没有,没有任何事情发生.)
  3. FIRST 手段 find the first available, ignore rest

  • 精美的图片-比在这些东西上通常看到的文字文档墙要好得多。 (2认同)
  • 一些注意事项:“交互式 shell”应该是“交互式,非登录 shell”,“登录 shell”应该是“交互式,登录 shell”。另外,至少在 Ubuntu 上,对于非登录交互式 shell,首先读取 `/etc/bash.bashrc`,然后读取 `~/.bashrc`。请注意,“/etc/bash.bashrc”不在普通的 GNU Bash 中,它是许多发行版所做的修改。 (2认同)

A B*_*A B 6

你的shell可能是一个登录shell,在这种情况下,bash将按顺序读取各种配置文件:

  1. /etc/profile
  2. ~/.bash_profile
  3. ~/.bash_login
  4. ~/.profile

通常~/.bashrc从其中一个文件中获取源代码,因此您也可以获得相同的登录shell配置.

这是我的~/.profile内容:

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
export LANGUAGE="en_US:en"
export LC_MESSAGES="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_COLLATE="en_US.UTF-8"
Run Code Online (Sandbox Code Playgroud)