linux环境变量

本文介绍了Shell环境下的变量类型,包括set、env和export的区别,并详细解释了系统级与用户级配置文件的作用及加载时机。同时给出了.bash_profile和.bashrc的具体配置示例。

set :当前shell变量

env:当前用户变量,和用户有关,与shell无关

export:导出为用户变量的shell变量

 

配置文件分为系统级(每个 用户都需要读取)变量(/etc/profile&/etc/bashrc)与用户级变量(~/.profile&~/.bashrc)

profile:登录时载入

.bashrc:普通shell启动时载入

尽管login bash启动时不会自动执行.bashrc,惯例上会在.bash_profile中显式调用.bashrc.编辑.bash_profile修改当前用户的环境变量修改完成之后source一下即可生效,例如source ~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

 

bashrc参考

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

 

转载于:https://my.oschina.net/hnuweiwei/blog/876220

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值