上篇文章講解了 profile 文件的作用、login shell 和 non-login shell 的定義、不同 profile 被 bash shell 在不同情況下的加載順序和作用,本文講解一下 zsh shell 相關(guān)的知識。
zsh shell
?MacOS 從 Catalina 版本開始將 zsh 作為默認(rèn)登錄 shell 和交互式 shell。
zsh 的配置文件加載順序大致如下:
- /etc/zshenv:這是zsh啟動時的第一個配置文件,全局生效,對所有用戶都有效。
- ~/.zshenv:這是針對每個用戶的第一個配置文件,對單個用戶有效。
- /etc/zsh/zshrc:這是zsh的默認(rèn)配置文件,對所有用戶有效。
- ~/.zshrc:這是每個用戶的默認(rèn)配置文件,對單個用戶有效。
- ~/.zprofile、~/.zsh、~/.zlogin、~/.zlogout:這些文件是針對每個用戶的登錄和退出腳本,對單個用戶有效。
zsh shell 是不會執(zhí)行 /etc/profile 和 ~/.bash_profile 文件的,當(dāng)從 bash 切換為 zsh 時,如果不想再配置一遍 ~/.zshrc 文件,可以在 ~/.zshrc 文件中加上?source ~/.bash_profile,以直接從 ~/.bash_profile 文件讀取配置。
如何查看當(dāng)前使用的 shell?
可以使用如下命令來查看當(dāng)前使用的 shell:
echo $SHELL
在我電腦上運(yùn)行效果如下:
$ echo $SHELL
/bin/zsh
可以使用如下命令查看系統(tǒng)中安裝了哪些 shell:文章來源:http://www.zghlxwxcb.cn/news/detail-635412.html
cat /etc/shells
在我電腦上運(yùn)行效果如下:文章來源地址http://www.zghlxwxcb.cn/news/detail-635412.html
cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
到了這里,關(guān)于Linux 和 MacOS 中的 profile 文件詳解(二)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!