Can't change shell from zsh to bash?

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:~$ 
2

2 Answers

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
  1. chsh -s /bin/bash (enter password when prompted)
  2. Log out
  3. Log back in
  4. echo $SHELL to confirm

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like