ubuntu每次打开命令窗口(开机)都要重新source pro
问题描述
- 在Ubuntu 18.04.1 LTS中配置JAVA环境,每次重新打开命令行都要重新source profile
解决办法
- 把export语句写在~/.bashrc文件里,或者在该文件里写上source /etc/profile
原因分析与记录
- bashrc是在系统启动后就会自动运行
- profile是在用户登录后才会运行
- /etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量
延伸:login shell 与 non-login shell
- non-login shell:登录终端不需要密码,例如直接在ubunt当前用户中打开的终端。这种情况shell不会读取/etc/profile和/.bash_profile,而是读取/.bashrc来应用新的环境变量。
- login shell:需要输入密码登录的shell,例如通过 su 用户名 登录的shell。此种方式登录时,shell会重新读取/etc/profile和~/.bash_profile来应用新的环境变量。
- 识别非login的shell方法还是运行#echo $0命令,得到的结果假设没有'-'前缀。即为非login的
注意
- non-login shell 启动的脚本不会入/etc/profile中的命令,所以在在/etc/profile中设置的某些命令不会生效,可能会导致一些问题,需要格外注意。
本文标题:ubuntu每次打开命令窗口(开机)都要重新source pro
本文链接:https://www.haomeiwen.com/subject/jurqtqtx.html
网友评论