linux的环境变量添加读取

变量加载文件

在linux中添加环境变量该如何添加?
文件夹
	  /etc/profile.d/
文件
    /etc/profile
    /etc/bashrc
    ~/.bash_rc
    ~/.bash_profile


	
顾名思义,linux打开之后程序会自动运行以上文件 若添加环境便量则依次从文件中寻找 若重复则覆盖

增加环境便量有两种方式:
1.临时添加
2.永久添加

# 进入 vim ~/.bashrc
增加环境便量:export LINUX_NAME=CentOS、
编写环境便量的格式:export PYTHON_HOME='D:/python'

查看本机的环境便量:
echo $PYTHON_HOME : 查看某一个环境便量
printenv : 产看所有的环境便量

读取环境变量

# 重启以及切换用户,并测试使用文件的先后顺序
1、重启
  /etc/profile.d --> /etc/profile --> /etc/bashrc --> ~/.bashrc --> ~/.bash_profile
		
2、切换用户
  /etc/profile.d --> /etc/bashrc --> ~/.bashrc
		
3、重新登录用户
1、su - [用户名]
  /etc/profile.d --> /etc/profile --> /etc/bashrc --> ~/.bashrc --> ~/.bash_profile
			
2、ssh root@192.168.15.101
  /etc/profile.d --> /etc/profile --> /etc/bashrc --> ~/.bashrc --> ~/.bash_profile

将环境变量添加到/etc/profile.d 或 /etc/bashrc 是指所有的用户均生效
使环境变量对当前用户生效 ~/.bash_profile

知识储备:
# 创建用户
  useradd [用户名] --> useradd jiji
# 切换用户
  su [用户名] ---> su jiji

# 即为重启
重新登录用户:
1)格式: su - [用户名]
"""
[jiji@localhost root]$ su - root
密码:******
上一次登录:一 12月 13 19:32:31 CST 2021从 192.168.15.1pts/3 上
[root@localhost ~]# 
"""
环境变量顺序:
/etc/profile.d --> /etc/profile --> /etc/bashrc --> ~/.bashrc --> ~/.bash_profile
	
2)格式:ssh root@192.168.15.101
/etc/profile.d --> /etc/profile --> /etc/bashrc --> ~/.bashrc --> ~/.bash_profile
posted @ 2021-12-13 20:43  谢俊杰  阅读(456)  评论(0编辑  收藏  举报