319

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?

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
vpoola88
  • 3,669
  • 4
  • 20
  • 21

12 Answers12

621

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.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • 1
    Or, just invoke zsh, and when you’re done `exit` to get back to bash. Exec’ing it seems unnecessary and undesirable. – Chris Page May 03 '12 at 07:32
  • All depends on what you expect your terminal window to do when you exit. I find starting a subshell unnecessary and undesirable, myself. – larsks May 03 '12 at 15:40
  • 3
    How do you change the default? Also, when I do "exec bash" in zsh, it does not source my bash_profile. – Harshad Kale Jan 11 '14 at 17:59
  • 1
    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!! – Bob Roberts Jan 20 '17 at 04:55
  • 1
    But if you run `echo $SHELL` it keep saying `/bin/zsh`, which have unexpected results like [this problem with MC (bug 3580)](https://midnight-commander.org/ticket/3580). – Pablo Bianchi Apr 28 '18 at 23:32
  • @kalehv `chsh -s /bin/zsh` will change the default. to source any executable including your .bash_profile do `. {filename}` – barclay Feb 10 '21 at 16:34
235

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.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
wanghao
  • 3,335
  • 2
  • 18
  • 13
85

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
phil-ociraptor
  • 1,041
  • 8
  • 5
  • 2
    Thanks phill, I installed thoughtbot/laptop and it mess all my configs. Your tip helps to get my bash environment back. – Seralto Oct 01 '15 at 13:45
  • 3
    Would be useful hat you wrote what is "--login" for? – Ewoks Jan 09 '18 at 02:35
  • 1
    `Make bash act as if it had been invoked as a login shell (see INVOCATION below).` [Source](http://manpages.ubuntu.com/manpages/precise/en/man1/bash.1.html) – lony May 18 '20 at 06:43
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)

Rahil
  • 257
  • 2
  • 5
20

For Bash, try

chsh -s $(which bash)

For zsh, try

chsh -s $(which zsh)
Pang
  • 9,564
  • 146
  • 81
  • 122
as - if
  • 2,729
  • 1
  • 20
  • 26
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.

Kalhara Tennakoon
  • 1,302
  • 14
  • 20
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

ljcusack
  • 61
  • 1
  • 2
  • 1
    Not clear though what version of bash it will emulate, will it emulate bash 4.x? or 5.x? –  Aug 15 '19 at 16:14
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

Sarah A
  • 1,185
  • 12
  • 27
5

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!

tom
  • 21,844
  • 6
  • 43
  • 36
kushagra deep
  • 462
  • 6
  • 12
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.

Paul Jurczyk
  • 164
  • 6
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.

Aleks
  • 4,866
  • 3
  • 38
  • 69
-7

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

Rajani
  • 13