bash - 在 MacOS 中使 ZSH 默认 Shell

标签 bash shell zsh

<分区>

我在我的 Mac 上安装了 zsh。现在我想让它成为默认的 shell 而不是 Bash。但我似乎遇到了以下错误:

$ echo $SHELL
/bin/bash
$ chsh -s /usr/bin/zsh
Changing shell for harshamv.
Password for harshamv:
chsh: /usr/bin/zsh: non-standard shell

最佳答案

正确答案应该已经解决了您的问题:

chsh: /usr/bin/zsh: non-standard shell

出现这种情况的原因是 chsh 将只接受在文件/etc/shells 中定义的 shell,正如您阅读 chsh 的手册所见>:

chsh will accept the full pathname of any executable file on the system. However, it will issue a warning if the shell is not listed in the /etc/shells file.

要解决此问题并使 zsh 成为默认 shell,您应该:

$ sudo echo "$(which zsh)" >> /etc/shells
$ chsh -s $(which zsh)

显然,我假设 zsh 在您的路径中。例如,如果您选择使用 brew install zsh 安装最新的 zsh,此解决方案也适用。

编辑(感谢 ThisIsFlorianK 的评论):

根据您的 shell 设置,您可能会收到一条消息,内容为 /etc/shells: Permission denied。您可以找到有关此问题的信息 here. 要解决此问题,请改用以下内容:

$ sudo sh -c "echo $(which zsh) >> /etc/shells"
$ chsh -s $(which zsh)

关于bash - 在 MacOS 中使 ZSH 默认 Shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31034870/

相关文章:

linux - Bash 脚本不会生成 cat 的子进程

linux - Bash 脚本在重启后继续吗?

php - 不能用find和exec移动?

python - docker exec 上的 Heredoc

ruby-on-rails - zsh:将 AWS key 添加为环境变量时解析 `\n' 附近的错误

macos - 为什么 $PATH 在 shell 登录后会被覆盖?

bash - 'ls' 参数是否有既定顺序?

linux - wget 下载未完成所有页面

c - 终端如何从标准输出读取并在屏幕上绘制文本?

bash - 如何查找名称以 "a"开头的文件?