2

我是 bash 脚本中的新手。我正在尝试在 .bashrc 文件中添加一行:

## make python 2.7 default in ~/.bashrc
echo 'export PATH=/usr/local/lib/python/bin:$PATH' >> ~/.bashrc  
source ~/.bashrc  

source 命令不会重新加载 ~/.bashrc 文件。(但如果我在提示下这样做就可以了)

如何从脚本中重新加载 .bashrc ?任何帮助将不胜感激。

干杯

4

1 回答 1

1

啊哈!现代 *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可能会突然开始从脚本加载!

于 2013-08-16T11:36:03.523 回答