~/.profile 在终端打开时没有被执行?[OS X 10.6.8]

5 bash prompt macos

不知何故,我的 bash 提示更改为“elementary:~ steven$”,我想将其改回默认提示。我首先将以下内容添加到 ~/.bashrc 然后添加到 ~/.profile:

export PS1="\s-\v\$ "
Run Code Online (Sandbox Code Playgroud)

当我打开终端时都不会被执行。如果我source在任一文件上运行该命令,它在该会话的其余部分都可以正常工作。

有什么我在这里俯瞰的吗?

编辑:这是伊恩建议的输出:

elementary:~ steven$ bash --login --verbose
# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi
/usr/libexec/path_helper -s
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/usr/local/AVRMacPack/bin"; export PATH;

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi
# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
   return
fi

PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
if [ -e "/usr/local/AVRMacPack" ]; then
PATH="$PATH:/usr/local/AVRMacPack/bin"
export PATH
fi

# Setting PATH for Python 3.2
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.2/bin:${PATH}"
export PATH
elementary:~ steven$ which bash
which bash
/bin/bash
Run Code Online (Sandbox Code Playgroud)

Ian*_* C. 6

.bashrc 根据 bash 手册页,仅对非交互式 shell 执行。

.bash_profile 为登录 shell 执行。

.profile文件由 Korn shell 加载。我不知道 bash 对此有任何关注。我在 bash 手册页中找不到任何对它的引用。

在 OS X 上,Terminal.app 程序为您打开的每个新 Terminal.app 窗口运行一个登录 shell。

所以你想把你的提示设置放在.bash_profile.

您始终可以在.bash_profile. 这并不少见,但我不能说它会产生什么样的影响:

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi
Run Code Online (Sandbox Code Playgroud)

那么你就不必维护两个文件。

  • `.profile` * 也被 bash 读取,但前提是 `.bash_profile` 不存在。 (2认同)

Zam*_*nji 0

我可能是不正确的,但如果 bash 是你的 shell,你必须将其放在你的 ~/.bash_profile 而不是你的 .bashrc 中。