linux中profile.d和profile的区别

profile.d在profile中加载

profile文件

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/scripts:/soc/bin:/soc/scripts"
LD_LIBRARY_PATH="/usr/local/lib:/usr/lib:/opt/lib:/soc/lib"
export SSL_LDPATH=/usr/local/lib/
export ZLIB_LDPATH=/usr/local/lib/

export PATH
export LD_LIBRARY_PATH
export TERM=vt102
export TERMINFO=/usr/share/terminfo
export TZ=CTS-8

ulimit -s 2048

if [ "$PS1" ]; then
        if [ "`id -u`" -eq 0 ]; then
                export PS1='$PWD # '
        else
                export PS1='$PWD $ '
        fi
fi

export EDITOR='/bin/vi'

#use script to control npu BW
export SELECT_SCRIPT_CTRL_BW=enabled

# Source configuration files from /etc/profile.d
for i in /etc/profile.d/*.sh ; do
        if [ -r "$i" ]; then
                . $i
        fi
done
unset i

在 /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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值