profile.d和profile的区别

profile.d在profile中加载

在 /etc/profile 这个文件中有这么一段 shell, 会在每次启动时自动加载 profile.d 下的每个配置

if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i

区别

  • 都用来设置环境变量文件
  • /etc/profile.d/ 高度解耦, 比 /etc/profile 好维护,不想要什么变量直接删除 /etc/profile.d/ 下对应的 shell 脚本即可
  • /etc/profile 和 /etc/profile.d 同样是登录(login)级别的变量,当用户重新登录 shell 时会触发
  • 设置登录级别的变量,重新登录 shell,或者 source /etc/profile

需要添加新的环境变量时

在 /etc/profile.d/ 目录下新建对应的 sh 文件即可,比如新建 oracle 的:

vim /etc/profile.d/oracle19c.sh

添加内容

export  ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export  PATH=$PATH:/opt/oracle/product/19c/dbhome_1/bin
export  ORACLE_SID=ORA19C

使能

source /etc/profile

查看环境变量

echo $ORACLE_SID

论读书
睁开眼,书在面前
闭上眼,书在心里
原文地址:https://www.cnblogs.com/YC-L/p/14602415.html