1

I am trying to add Xonsh to my /etc/shellsto make it my new default shell, however when i run sudo which xonsh >> /etc/shells I get bash: /etc/shells: Permission denied I tried changing the permissions using chmod u+x /etc/shellsbut it throws changing permissions of '/etc/shells': Operation not permitted what can i do?

  • Did you try `chmod` without `sudo` or did you just forget to include that in your question? – zaen Jun 07 '23 at 15:04
  • 3
    Does this answer your question? [How to append to a file as sudo?](https://superuser.com/questions/136646/how-to-append-to-a-file-as-sudo) – Jeff Schaller Jun 07 '23 at 15:18

1 Answers1

1

The output redirection >> is perhaps tried to be applied by the shell before the sudo is executed, but the user shell has no permission to do that.

To avoid the error, the following two formulations might work :

sudo sh -c "echo $(which xonsh) >> /etc/shells"

echo $(which xonsh) | sudo tee -a /etc/shells
harrymc
  • 455,459
  • 31
  • 526
  • 924