Iam newbee在bash脚本中。 我想在.bashrc文件上添加一行:
## make python 2.7 default in ~/.bashrc
echo 'export PATH=/usr/local/lib/python/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
source命令没有重新加载〜/ .bashrc文件。 (但如果我在提示时这样做,则有效)
如何从脚本重新加载.bashrc? 任何帮助都会受到更多的赞赏。
干杯
答案 0 :(得分: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
可能会突然从脚本中开始加载!