.bashrc not work

今天想 在 .bashrc 中配置一段自动启动 ssh-agent 的脚本,结果总是没有自动运行;才发现我的 bashrc 脚本没有自动 加载

后来才发现是这次装的深度系统(deepin)默认没有 ~.profile脚本, 去看看之前的ubuntu系统里面都默认是有这个脚本的,而 ~.bashrc 脚本则是通过 .profile 来加载的

如果新建一个用户, 在其 $HOME 目录下会自动创建 .profile 脚本吗?

1. linux系统加载bash配置脚本的顺序

.bashrc 文件本身在 *nix 系统下就不会自动加载,一般都是通过 .profile 间接加载的

一般,系统会按下面的顺序加载

/etc/profile
~/.bash_profile
~/.bash_login
~/.profile

如果你的.bashrc 没有自动加载,就新建 ~/.profile

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi  
fi

mesg n        

当然如果, 已经有了 .bash_profile or .bash_login, 那么这个 .profile 文件也不会被加载。 总之,是把 此段代码写到 已经存在的 最先被加载到的那个配置中。

refer to :

http://askubuntu.com/questions/260682/bashrc-not-autosourced-in-12-04-lts
http://apple.stackexchange.com/questions/12993/why-doesnt-bashrc-run-automatically

2. Difference Between .bashrc & .bash_profile

.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

  1. 当你直接在机器login界面登陆、使用ssh登陆或者su切换用户登陆时,.bash_profile 会被调用来初始化shell环境
    Note:.bash_profile文件默认调用.bashrc文件

  2. 当你不登陆系统而使用ssh直接在远端执行命令,.bashrc 会被调用

  3. 你已经登陆系统后,每打开一个新的Terminal时,.bashrc 都会被再次调用。

若要配置环境变量之类,最保险是写在 .bashrc 文件中。因为不管是登陆还是不登陆,该文件总会被调用

refer to :

http://upgirl.blog.51cto.com/3744514/1140176

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值