bash - 无法在 macOS 上修改/etc/shells 以包含 brew 安装的 bash 版本

标签 bash macos shell homebrew

我正在尝试更新我的 /etc/shells文件以包含 bash 的 Homebrew 软件安装版本的路径位于 /usr/local/bin/bash$ sudo echo /usr/local/bin/bash >> /etc/shells返回权限被拒绝,不允许尝试手动更新,因为它似乎是只读的。

检查文件后,权限设置如下:
-rw-r--r-- 1 root wheel 179 Feb 21 2017 /etc/shells
所以,考虑到这一点,并在看了这个 article 之后关于使用 Homebrew 更新 shell 我尝试以 root 用户身份启动 shell,然后尝试上面的命令,即:

$ sudo -s
$ echo /usr/local/bin/bash >> /etc/shells
$ chsh -s /usr/local/bin/bash

但是,这似乎卡在第一个命令( $ sudo -s )上。这会产生一个 bash进程占用了大约 70% 的 CPU 而什么也没有发生。

有没有其他方法可以更新 /etc/shells/文件?

最佳答案

An approach to adding to a root-only file is echo /usr/local/bin/bash | sudo tee -a /etc/shells. – Petesh



Would you be able to explain why that works and the sudo echo /usr/local/bin/bash >> /etc/shells does not though.



后者不起作用,因为输出重定向 >>sudo … 之前由 shell 应用(试图)被执行,当然用户 shell 没有权限这样做。

关于bash - 无法在 macOS 上修改/etc/shells 以包含 brew 安装的 bash 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49048720/

相关文章:

linux - revbeal 密码输入字段的 HTML 按钮

bash - awk(或其他)如何强制字段号保持不变?

linux - 使用脚本提取文本

python - 采购 python 脚本

linux - 获取当前日期并将其用于文件名

bash - 在 bash for 循环中分离进程

macos - 在我的应用程序包装脚本启动后,如何使停靠栏图标停止弹跳?

macos - 在 Mac OS X 中获取进程创建通知

macos - 找不到-ltensorflow

linux - 在BASH中,我们可以赋值并显示变量_(下划线)中的值吗?