在 OSX 上从 zsh 切换到 bash,然后再返回?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10341271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 21:59:34  来源:igfitidea点击:

Switching from zsh to bash on OSX, and back again?

bashterminalzsh

提问by vpoola88

So Im 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 lay out of bash in some situations. How do I switch back and forth, or turn zsh on and off? Thanks!

所以我正在学习在 Rails 中开发,并且发现了 zsh 的强大功能。但是,对于我的其他一些任务,我希望使用普通的 Bash。虽然它们是相同的,但我只是在某些情况下对 bash 的布局感到满意。如何来回切换,或打开和关闭 zsh?谢谢!

回答by larsks

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

您可以使用exec新外壳替换当前外壳:

Switch to bash:

切换到bash

exec bash

Switch to zsh:

切换到zsh

exec zsh

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

这不会影响新的终端窗口或任何东西,但很方便。

回答by wanghao

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

您可以尝试chsh -s /bin/bash将bash设置为默认值,或者chsh -s /bin/zsh将zsh设置为默认值。

回答by phil-ociraptor

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

我经常在 zsh 和 bash 之间切换。有一段时间,我曾经不得不在每次切换时获取我的 bash_profile。然后我发现你可以(通常)做

exec bash --login

or just

要不就

exec bash -l

回答by Rahil

if it is just a temporary switch

如果只是临时切换

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

您可以使用上面提到的 exec ,但更多的是永久解决方案。

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

您可以使用chsh -s /bin/bash(切换到 bash)和chsh -s /bin/zsh(切换到 zsh)

回答by as - if

For Bash, try

对于 Bash,请尝试

chsh -s $(which bash)

For zsh, try

对于 zsh,请尝试

chsh -s $(which zsh)

回答by ljcusack

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

zsh 有一个内置命令emulate,它可以通过设置适当的选项来模拟不同的 shell,尽管 csh 永远不会被完全模拟。

emulate bash
perform commands
emulate -R zsh

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

-R 标志将所有选项恢复为该 shell 的默认值。

See: zsh manual

参见:zsh手册

回答by Paul Jurczyk

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

您应该能够bash在终端中键入以切换到 bash,然后键入zsh以切换到 zsh。至少对我有用。

回答by Randil Tennakoon

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

在 Mac OS Catalina 中,默认的交互式 shell 是 zsh。要将 shell 从 bash 更改为 zsh:

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.

然后你需要输入你的 Mac 密码。退出终端并重新打开它。要检查它是否已成功更改为 ssh,请发出以下命令。

echo $SHELL

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

如果结果是/bin/zsh,则您的任务已完成。

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

要将其改回 bash,请在终端上发出以下命令。

chsh -s /bin/bash

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

使用 再次验证它echo $SHELL。那么结果应该是/bin/bash。

回答by Rajani

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

您可以使用命令“bye”轻松切换回 bash