tallamjr
tallamjr

Reputation: 1470

Unable to modify /etc/shells on macOS to include brew installed version of bash

I am trying to update my /etc/shells file to include the path to a homebrew installed version of bash which resides at /usr/local/bin/bash

$ sudo echo /usr/local/bin/bash >> /etc/shells returns Permission denied and attempting to manually update is not allowed as it appears to be read-only.

Upon inspecting the file, the permissions are set as follows:

-rw-r--r-- 1 root wheel 179 Feb 21 2017 /etc/shells

So, with this in mind, and after looking at this article about Updating you shell with Homebrew I tried to initiate a shell as the root user and then try command above, i.e:

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

However, this seems to hang on the first command ($ sudo -s). This spawns a bash process that eats up ~ 70% CPU and nothing happens.

Is there an alternative way one can update the /etc/shells/ file?

Upvotes: 5

Views: 12189

Answers (2)

MagicDude4Eva
MagicDude4Eva

Reputation: 145

Or you can just use this (I had to do this on macOS Mojave):

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

Upvotes: 3

Armali
Armali

Reputation: 19395

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.

The latter doesn't work because the output redirection >> is (tried to be) applied by the shell before the sudo … is executed, and of course the user shell has no permission to do that.

Upvotes: 18

Related Questions