has*_*ste 30 linux shell bash bashrc
bash.bashrc除非我bash从终端手动运行,否则不会从交互式终端获取源:
$ bash
Run Code Online (Sandbox Code Playgroud)
或手动获取它:
$ source ./.bashrc
Run Code Online (Sandbox Code Playgroud)
或运行:
$ st -e bash
Run Code Online (Sandbox Code Playgroud)
我希望这是一些有用的输出:
$ echo $TERM
st-256color
$ echo $SHELL
/bin/sh
$ readlink /bin/sh
bash
$ shopt login_shell
login_shell off
Run Code Online (Sandbox Code Playgroud)
我在 CRUX Linux 3.0 上,我使用dwm和st. 我已经尝试使用.bash_profile并.profile没有成功。
有任何想法吗?
Jei*_*ght 36
在 .bash_profile 中确保您有以下内容:
# .bash_profile
# If .bash_profile exists, bash doesn't read .profile
if [[ -f ~/.profile ]]; then
. ~/.profile
fi
# If the shell is interactive and .bashrc exists, get the aliases and functions
if [[ $- == *i* && -f ~/.bashrc ]]; then
. ~/.bashrc
fi
Run Code Online (Sandbox Code Playgroud)
ter*_*don 20
为什么要采购它?你没有运行 true bash:
$ echo $SHELL
/bin/sh
Run Code Online (Sandbox Code Playgroud)
在大多数现代系统中,sh是基本 shell 的符号链接。例如在我的 Debian 上:
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Aug 1 2012 /bin/sh -> dash
Run Code Online (Sandbox Code Playgroud)
在您的情况下,sh是指向bash但是的链接,如中所述man bash:
如果使用名称 sh 调用 bash,它会尝试尽可能模仿 sh 历史版本的启动行为,同时也符合 POSIX 标准。[...] 当作为名为 sh 的交互式 shell 调用时,bash 查找变量 ENV,如果已定义则扩展其值,并使用扩展值作为要读取和执行的文件名。由于作为 sh 调用的 shell 不会尝试从任何其他启动文件读取和执行命令,因此 --rcfile 选项无效。
和
--norc
如果 shell 是交互式的,则不要读取和执行系统范围的初始化文件 /etc/bash.bashrc 和个人初始化文件 ~/.bashrc。 如果 shell 作为 sh 调用,则默认情况下此选项处于启用状态。
因此,由于您的默认 shell 是sh,.bashrc不会被读取。只需使用 .bash 将默认 shell 设置为 bash 即可chsh -s /bin/bash。