解决:zsh环境下,/etc/profile.d文件夹下的脚本不执行

解决:zsh环境下,/etc/profile.d文件夹下的.sh脚本不执行

如果你懒得看过程,请直接将文末代码粘贴到/etc/zsh/zprofile中。

1 问题描述

  • 安装了zsh后,当我按照conda的提示将conda.sh添加到/etc/profile.d文件夹后并没有生效。

2 解决过程

  1. 查看zsh官方文档,大致了解了/etc/zsh目录下的各个文件作用。
  2. 在文档中看到这一行字。
    Warning: Do not remove the default one line in /etc/zsh/zprofile, otherwise it will break the integrity of other packages which provide some scripts in /etc/profile.d/.
    来自zsh文档
  3. 也就是说,/etc/zsh/zprofile文件里面有一行默认的文字,与/etc/profile.d文件夹下的脚本有关。然而当我们打开zprofile文件只看到有一堆注释,所以显然缺少了这行默认文字。
  4. 至此可以推测/etc/zsh/zprofile文件对应的是/etc/profile文件,我们把/etc/profile文件中用来执行/etc/profile.d/下脚本的命令复制到zprofile中,问题解决~~
if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
发布了2 篇原创文章 · 获赞 0 · 访问量 121

猜你喜欢

转载自blog.csdn.net/weixin_43558951/article/details/104346652
今日推荐