.bashrc中配置环境变量不生效

问题描述

在.bashrc文件中配置环境变量 export PATH="$PATH:$HOME/Library/Python/3.8"后,运行了命令source ~/.bashrc 执行pipenv命令有效,然后新开一个终端后,提示 command not found

原因

执行source ~/.bashrc 后生效,说明配置成功了,新打开终端未生效说明新打开终端时未加载 .bashrc文件。
因为配置的环境是Mac,而Mac OS环境变量的默认配置文件为~/.zshrc, 所以在~/.zshrc·中添加source ~/.bashrc即可

由于经常遇到此类环境变量配置问题,了解了一下login shell 和 non-login shell的区别,

login shell 和 non-login shell

login shell 读取/etc/profile, 然后依次读取~/.bash_profile, ~/.bash_login, and ~/.profile,如果已找到则后面的文件不会被读取
non-login shell 读取~/.bashrc来应用新的环境变量,比如在已打开的终端再输入bash,未输入密码,那么新开的bash就是non-login的(如果输入的bash --login 则还是login shell)
同理su user ,su - user分别标识non-login shell和login shell,通过man su查看的解释

.......
-, -l, --login
              Start the shell as a login shell with an environment similar to a real login:
......              

通过shopt -q login_shell && echo 'Login shell' || echo 'Non-login shell'可以知道是login shell or non-login shell

interactive 和 non-interactive shell

交互式shell:在终端输入命令
非交互式shell: 执行shell scriptss
通过命令[[ $- == *i* ]] && echo 'Interactive shell' || echo 'Non-interactive shell' 可以知道是interactive还是non-interactive shell

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值