首页 文章

.bashrc无法从脚本重新加载

提问于
浏览
2

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?任何帮助将更加欣赏 .

干杯

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 会突然从脚本开始加载!

相关问题