linux变量加载文件 linux环境变量 读取环境变量的先后顺序

变量加载文件

在linux添加环境变量:

	文件:
    	/etc/profile
        /etc/bashrc
        ~/.bash_profile
        ~/.bash_rc
        
     文件夹:
        /etc/profile.d/
        
        
增加环境变量的两种方式 :
		1. 临时添加
    	2. 永久添加 
   

增加环境变量的格式:
	export 变量名=变量值
    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
    # 故: 如果想环境变量对任何用户都适用:就添加到/etc/profile.d --> /etc/bashrc
    	知识储备:
    		创建用户:useradd [用户名]
    		切换用户:su [用户名]
    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
    
    
posted @ 2021-12-13 19:42  JasonBorn  阅读(161)  评论(0编辑  收藏  举报