网站首页 > 博客文章 正文
操作系统:Centos 7.9
使用 /etc/profile.d 而不是 /etc/profile 来配置环境变量 Linux
在 /etc/profile 这个文件中有这么一段 shell, 会在每次启动时自动加载 profile.d 下的每个配置.
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
通过这段代码,/etc/profile会执行/etc/profile.d/目录下的所有*.sh文件。
区别
1、都用来设置环境变量文件
2、/etc/profile.d/ 高度解耦, 比 /etc/profile 好维护,不想要什么变量直接删除 /etc/profile.d/ 下对应的 shell 脚本即可
3、/etc/profile 和 /etc/profile.d 同样是登录(login)级别的变量,当用户重新登录 shell 时会触发。所以效果一致。
4、设置登录级别的变量,重新登录 shell,或者 source /etc/profile。
在/etc/profile 文件中设置的变量是全局变量,是系统级别的,对所有用户都有效
参考链接:
https://blog.csdn.net/a308601801/article/details/86599512
https://blog.csdn.net/xu710263124/article/details/116647467
猜你喜欢
- 2024-11-27 CentOS服务器安装JDK8环境
- 2024-11-27 Centos7虚拟机搭建Hadoop集群环境教程
- 2024-11-27 聊聊Shell的种类,变量的分类,条件测试的表达
- 2024-11-27 Java环境快速搭建
- 2024-11-27 centos7安装软件-jdk,maven,git
- 2024-11-27 centos 7 安装部署流程 最全最细包成功
- 2024-11-27 CentOS,安装Redis5,Java客户端Jedis、Lettuce和Redisson对比
- 2024-11-27 Linux (Centos6.5)下安装java+jdk+tomcat(非yum安装)
- 2024-11-27 Linux CentOS服务器安装Python3.8环境
- 2024-11-27 如何查看Docker容器环境变量,如何向容器传递环境变量
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)