解决:zsh环境下,/etc/profile.d文件夹下的.sh脚本不执行
如果你懒得看过程,请直接将文末代码粘贴到
/etc/zsh/zprofile
中。
1 问题描述
- 安装了zsh后,当我按照conda的提示将
conda.sh
添加到/etc/profile.d
文件夹后并没有生效。
2 解决过程
- 查看zsh官方文档,大致了解了
/etc/zsh
目录下的各个文件作用。 - 在文档中看到这一行字。
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/.
- 也就是说,
/etc/zsh/zprofile
文件里面有一行默认的文字,与/etc/profile.d
文件夹下的脚本有关。然而当我们打开zprofile
文件只看到有一堆注释,所以显然缺少了这行默认文字。 - 至此可以推测
/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