linux环境变量总结

linux环境变量总结

本人测试的环境变量有

###系统级环境变量
#/etc/profile.d/test.sh
#/etc/profile
#/etc/environment
#/etc/bashrc

###用户级环境变量
#~/.bashrc
#~/.bash_profile

###如果想直接生效source

###读取环境变量的方法:
export      命令显示当前系统定义的所有环境变量
echo $PATH  命令输出当前的PATH环境变量的值

###测试
export ceshi="$ceshi:文件路径"

[root@MiWiFi-R4AC-srv ~]# echo $ceshi
$ceshi:/etc/environment:/etc/profile.d/test.sh:/etc/profile:/etc/bashrc:~/.bashrc:~/.bash_profile

####顺序为(本测试使用的centos7.4,其他版本和系统都有可能影响环境变量)
/etc/environment
/etc/profile.d/test.sh
/etc/profile
/etc/bashrc
~/.bashrc
~/.bash_profile

### 明白环境变量之间的顺序就可以防止覆盖等现象

###技巧
1.可以自定义文件,使用export定义一系列变量,在~/.bashrc文件中source,这样就可以在本用户中使用一系列自定义变量
2.也可用alias定义一系列别名
posted @ 2023-05-23 17:13  Bre-eZe  阅读(13)  评论(0)    收藏  举报