bash - .bashrc 未从脚本重新加载

标签 bash

我是 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/

相关文章:

linux - 如何在特定的/dev/ttyX(或/dev/pts/X)设备上启动 bash?

regex - 是否有使用正则表达式更改文件名的 grep 或 shell 脚本?

bash - 在路径变量中使用带空格的 perl system() 查询

linux - 通过 PIPE 发送 Unix/Linux SIGNAL

objective-c - 更改 MAC 地址 Cocoa - Objective-C

bash - 用于记录某些文件类型所在位置的 Ubuntu Shell 脚本

string - 如何在 awk 表达式中使用变量

linux - Shell脚本--如果子进程执行失败如何终止父进程

bash - 如何使用 bash 命令将 EMR 步骤添加到 cloudformation

sql - Bash 脚本 - 带引号的命令中的 If 语句