Linux 和 MacOS 中的 profile 文件详解(二)

上篇文章讲解了 profile 文件的作用、login shell 和 non-login shell 的定义、不同 profile 被 bash shell 在不同情况下的加载顺序和作用,本文讲解一下 zsh shell 相关的知识。

zsh shell

 MacOS 从 Catalina 版本开始将 zsh 作为默认登录 shell 和交互式 shell。

zsh 的配置文件加载顺序大致如下:

  1. /etc/zshenv:这是zsh启动时的第一个配置文件,全局生效,对所有用户都有效。
  2. ~/.zshenv:这是针对每个用户的第一个配置文件,对单个用户有效。
  3. /etc/zsh/zshrc:这是zsh的默认配置文件,对所有用户有效。
  4. ~/.zshrc:这是每个用户的默认配置文件,对单个用户有效。
  5. ~/.zprofile、~/.zsh、~/.zlogin、~/.zlogout:这些文件是针对每个用户的登录和退出脚本,对单个用户有效。

zsh shell 是不会执行 /etc/profile 和 ~/.bash_profile 文件的,当从 bash 切换为 zsh 时,如果不想再配置一遍 ~/.zshrc 文件,可以在 ~/.zshrc 文件中加上 source ~/.bash_profile,以直接从 ~/.bash_profile 文件读取配置。

如何查看当前使用的 shell?

可以使用如下命令来查看当前使用的 shell:

echo $SHELL

在我电脑上运行效果如下:

$ echo $SHELL    
/bin/zsh

可以使用如下命令查看系统中安装了哪些 shell:

cat /etc/shells

在我电脑上运行效果如下:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路多辛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值