358

I'm learning to develop in Rails, and have discovered the power of zsh. However, for some of my other tasks, I wish to use normal bash.

Although they are the same, I just feel comfortable with the layout of bash in some situations.

How do I switch back and forth, or turn zsh on and off?

13 Answers 13

687

You can just use exec to replace your current shell with a new shell:

Switch to bash:

exec bash 

Switch to zsh:

exec zsh 

This won't affect new terminal windows or anything, but it's convenient.

Sign up to request clarification or add additional context in comments.

6 Comments

Or, just invoke zsh, and when you’re done exit to get back to bash. Exec’ing it seems unnecessary and undesirable.
All depends on what you expect your terminal window to do when you exit. I find starting a subshell unnecessary and undesirable, myself.
How do you change the default? Also, when I do "exec bash" in zsh, it does not source my bash_profile.
There are times when I want to use zsh and other times when it interferes with what I want to do. Setting the default back and forth is a bad idea so this is the perfect solution!!! kudos!!
But if you run echo $SHELL it keep saying /bin/zsh, which have unexpected results like this problem with MC (bug 3580).
|
272

you can try chsh -s /bin/bash to set the bash as the default, or chsh -s /bin/zsh to set the zsh as the default.

Terminal will need a restart to take effect.

4 Comments

Not entirely true. One can simply enter command: "bash", or "zsh" to use that shell.
I don't think this work anymore in 2022
@user1034912 Worked just fine for me, just now
Doesn't work in Tahoe 26.1 ---------- user -zhs - 120 x 30 user@mac-1013 ~ % chsh -s /bin/bash Changing shell for user. Password for user: user@mac-1013 ~ % Quit and launch new shell user -zhs - 120 x 30 user@mac-1013 ~ % Guess we're stuck with mandatory zhs.
90

I switch between zsh and bash somewhat frequently. For a while, I used to have to source my bash_profile every switch. Then I found out you can (typically) do

exec bash --login 

or just

exec bash -l 

3 Comments

Thanks phill, I installed thoughtbot/laptop and it mess all my configs. Your tip helps to get my bash environment back.
Would be useful hat you wrote what is "--login" for?
Make bash act as if it had been invoked as a login shell (see INVOCATION below). Source
24

if it is just a temporary switch

you can use exec as mentioned above, but for more of a permanent solution.

you can use chsh -s /bin/bash (to switch to bash) and chsh -s /bin/zsh (to switch to zsh)

2 Comments

Mine is zsh right now but when I try chsh -s /bin/bash and type my password it show no changes made
Yup, this solution doesn't work in Tahoe.
22

For Bash, try

chsh -s $(which bash) 

For zsh, try

chsh -s $(which zsh) 

Comments

8

In Mac OS Catalina default interactive shell is zsh. To change shell to zsh from bash:

chsh -s /bin/zsh 

Then you need to enter your Mac password. Quit the terminal and reopen it. To check whether it's changed successfully to ssh, issue the following command.

echo $SHELL 

If the result is /bin/zsh, your task is completed.

To change it back to bash, issue the following command on terminal.

chsh -s /bin/bash 

Verify it again using echo $SHELL. Then result should be /bin/bash.

Comments

7

you can just type bash or if you always want to use bash:

on "iTerm2"

  • Go to preferences > Profiles > Command
  • Select "Command" from the dropdown
  • Type bash

Test by closing iTerm and open it again

Comments

7

Follow the below steps:

chsh -s /bin/bash
Restart terminal
Check which shell is in use: echo $SHELL
source .profile

You are back with Bash!

2 Comments

Users need to wait little bit before Restart terminal
Restart the terminal to see the change.
6

zsh has a builtin command emulate which can emulate different shells by setting the appropriate options, although csh will never be fully emulated.

emulate bash perform commands emulate -R zsh 

The -R flag restores all the options to their default values for that shell.

See: zsh manual

1 Comment

Not clear though what version of bash it will emulate, will it emulate bash 4.x? or 5.x?
6

You should be able just to type bash into the terminal to switch to bash, and then type zsh to switch to zsh. Works for me at least.

3 Comments

This is even simpler.
This does work, but each time you type zsh or bash you are going into a sub-shell (subprocess under current shell). You will need to type exit a number of times to return to the top-most shell.
this is much better.
3

You can achieve this also via the UI by the following steps.

Step 1: Go to Preferences -> Users & Groups

Step 2: Select the user and press the unlock button and follow by entering the password

Step 3: Right click on the user and then select Advanced Options

Step 4: Select /bin/bash as the Login Shell

enter image description here

Note: You need to restart the shell to take this into effect.

Comments

0

For me, the solution was this:

Edit:

sudo vi /etc/passwd 

Find your user, for me it was for example:

ubuntu:x:1000:1001::/home/ubuntu:/bin/sh 

For you it might be:

ubuntu:x:1000:1001::/home/ubuntu:/bin/zsh 

And change it to:

ubuntu:x:1000:1001::/home/ubuntu:/bin/bash 

If you want bash to be defaul, or the line above if you want it to be zsh by default.

1 Comment

This doesn't seem like it would work on recent macOS versions - /etc/passwd now has a warning at the top saying it's only used when macOS is in single user mode, and there were no user-added users in it as of Sequoia 15.3. It's safer to use chsh -s as mentioned in other answers.
-8

You can easily switch back to bash by using command "bye"

1 Comment

bye will exit zsh but not back to bash

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.