我正在尝试更新我的 /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/