Switching from zsh to bash on OS X, and back again?
Asked Answered
R

13

333

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?

Retinoscopy answered 26/4, 2012 at 20:52 Comment(0)
L
652

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.

Length answered 26/4, 2012 at 20:58 Comment(6)
Or, just invoke zsh, and when you’re done exit to get back to bash. Exec’ing it seems unnecessary and undesirable.Claudelle
All depends on what you expect your terminal window to do when you exit. I find starting a subshell unnecessary and undesirable, myself.Length
How do you change the default? Also, when I do "exec bash" in zsh, it does not source my bash_profile.Montez
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!!Bossy
But if you run echo $SHELL it keep saying /bin/zsh, which have unexpected results like this problem with MC (bug 3580).Subfusc
@kalehv chsh -s /bin/zsh will change the default. to source any executable including your .bash_profile do . {filename}Shoreless
S
243

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.

Snowbound answered 22/3, 2014 at 3:40 Comment(2)
Not entirely true. One can simply enter command: "bash", or "zsh" to use that shell.Jackscrew
I don't think this work anymore in 2022Linsang
C
86

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
Chirlin answered 24/10, 2014 at 21:46 Comment(3)
Thanks phill, I installed thoughtbot/laptop and it mess all my configs. Your tip helps to get my bash environment back.Baseburner
Would be useful hat you wrote what is "--login" for?Khaki
Make bash act as if it had been invoked as a login shell (see INVOCATION below). SourceButts
F
22

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)

Farewell answered 20/3, 2019 at 20:54 Comment(1)
Mine is zsh right now but when I try chsh -s /bin/bash and type my password it show no changes madeCrifasi
F
21

For Bash, try

chsh -s $(which bash)

For zsh, try

chsh -s $(which zsh)
Freetown answered 15/11, 2017 at 3:31 Comment(0)
C
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.

Calling answered 16/5, 2020 at 12:28 Comment(0)
C
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

Curiel answered 15/1, 2016 at 23:22 Comment(1)
Not clear though what version of bash it will emulate, will it emulate bash 4.x? or 5.x?Ecosystem
C
6

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

Communicant answered 15/6, 2020 at 19:17 Comment(0)
H
6

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!

Hulky answered 11/5, 2021 at 18:45 Comment(1)
Users need to wait little bit before Restart terminalSerai
D
4

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.

Dalmatic answered 20/7, 2018 at 2:12 Comment(3)
This is even simpler.Gwenora
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.Tahmosh
this is much better.Shreveport
S
1

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.

Sprightly answered 9/9, 2023 at 17:5 Comment(0)
A
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.

Amaris answered 7/2, 2023 at 21:46 Comment(0)
B
-8

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

Blanding answered 11/1, 2018 at 16:19 Comment(1)
bye will exit zsh but not back to bashKinnon

© 2022 - 2024 — McMap. All rights reserved.