我是 bash 脚本中的 newbee。 我正在尝试在 .bashrc 文件中添加一行:
## make python 2.7 default in ~/.bashrc
echo 'export PATH=/usr/local/lib/python/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
source 命令不会重新加载 ~/.bashrc 文件。 (但如果我在提示符下这样做就可以工作)
如何从脚本重新加载 .bashrc? 任何帮助将不胜感激。
干杯
最佳答案
啊哈!现代 *nix 系统通常有一个系统范围的bashrc
,其启动如下:
# System-wide .bashrc file for interactive bash(1) shells.
# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
...
stuff follows
如果您观察最后几行,问题就会变得显而易见。您没有以交互方式运行。在脚本中获取 bashrc
之前,将 PS1
设置为任意值,例如:
PS1='foobar'
很可能您的 bashrc
会突然开始从脚本加载!
关于bash - .bashrc 未从脚本重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18272315/