大多数系统默认的shell是bash,但是可以修改为其他shell。比如最近比较火的 oh-my-zsh 就是 zsh 的一种配置。安装好新的shell,使用 chsh 命令(即 change shell)即可设置为默认shell。
但是今天用 brew 安装最新的 zsh 后,使用
chsh -s /usr/local/bin/zsh
修改默认shell时,报错
chsh: /usr/local/bin/zsh: non-standard shell
但是直接运行 /usr/local/bin/zsh 却是正常的。
经查, /etc/shells 文件中,包含了 login shell 的列表,应用程序通过该文件来判断一个shell是不是合法。我的系统里该文件内容如下:
# 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/ksh /bin/sh /bin/tcsh /bin/zsh
因此,必须先将 /usr/local/bin/zsh 加入到此文件中,然后才能使用 chsh 命令将其设置为默认shell。