4

I've just installed zsh on Ubuntu 20.04 and decided to change it back to bash. I tried common way which is chsh but it doesn't work.

Reference: changing shell from zsh to bash

Current shell

wolf@linux:/home/wolf $ echo $SHELL 
/bin/zsh
wolf@linux:/home/wolf $ 

1st attempt

wolf@linux:/home/wolf $ sudo chsh -s /bin/bash
wolf@linux:/home/wolf $ echo $SHELL           
/bin/zsh
wolf@linux:/home/wolf $

2nd attempt

wolf@linux:~$ sudo chsh --shell=/bin/bash $USER
wolf@linux:~$ echo $SHELL
/bin/zsh
wolf@linux:~$ 

3rd attempt

wolf@linux:~$ chsh -s $(which bash)
Password: 
wolf@linux:~$ echo $SHELL
/bin/zsh
wolf@linux:~$ 

Even bash and exec bash do not work

wolf@linux:/home/wolf $ bash
wolf@linux:~$ echo $SHELL
/bin/zsh
wolf@linux:~$ exec bash
wolf@linux:~$ echo $SHELL
/bin/zsh
wolf@linux:~$ 
  • 3
    It doesn't change until you reboot. chsh changes your default shell in the /etc/passwd file. You can always just run /bin/bash to go back to bash for now. – Terrance Jan 02 '21 at 03:59
  • You could always use exec bash to replace the current shell with the command, in this case, the desired shell. It will destroy the previous shell process, thou. –  Jun 23 '21 at 19:51

2 Answers2

4

chsh changes the shell field in the password database, which is read on login. To see the effect of the change, you need to start a new login session - for example with su -:

Ex. confirm current login shell is bash:

steeldriver@DESKTOP:~$ getent passwd steeldriver
steeldriver:x:1000:1000:,,,:/home/steeldriver:/bin/bash
steeldriver@DESKTOP:~$ echo $SHELL
/bin/bash

Change the shell - the password database is updated immediately but the value of $SHELL doesn't change

steeldriver@DESKTOP:~$ chsh -s /usr/bin/zsh
Password:

steeldriver@DESKTOP:~$ getent passwd steeldriver steeldriver:x:1000:1000:,,,:/home/steeldriver:/usr/bin/zsh steeldriver@DESKTOP:~$ echo $SHELL /bin/bash

Now start a new login session:

steeldriver@DESKTOP:~$ su - steeldriver
Password:
steeldriver@DESKTOP-SPDO14V ~ % echo $SHELL
/usr/bin/zsh
steeldriver
  • 136,215
  • 21
  • 243
  • 336
3
  1. chsh -s /bin/bash (enter password when prompted)
  2. Log out
  3. Log back in
  4. echo $SHELL to confirm