bash 如何将 .bashrc 导出到 .zshrc?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/764600/
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
How can you export your .bashrc to .zshrc?
提问by Léo Léopold Hertz ??
I am trying to move to zsh from Bash.
我正在尝试从 Bash 转移到 zsh。
I put my .bashrc directly to my .zshrc, and it caused a lot of errors when I try to use Bash again.
我把我的 .bashrc 直接放到了我的 .zshrc 中,当我再次尝试使用 Bash 时,它导致了很多错误。
How can you export your .bashrc to .zshrc?
如何将 .bashrc 导出到 .zshrc?
回答by Ryne Everett
While lhunath's answer pushed me in the right direction, zsh does not seem to source .profile
automatically. Lot's of good info on this topic can be found on this superuser post.
虽然 lhunath 的回答将我推向了正确的方向,但 zsh 似乎并没有.profile
自动来源。在这个超级用户帖子中可以找到很多关于这个主题的好信息。
The adaption I'm using is putting common aliases and functions in .profile
and manually sourcing them as follows:
我正在使用的适应是将常见的别名和函数放入.profile
并手动获取它们,如下所示:
In ~/.bashrc
:
在~/.bashrc
:
source ~/.profile
In ~/.zshrc
:
在~/.zshrc
:
[[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'
emulate
is a zsh builtin command. With single argument set up zsh options to emulate the specified shell as much as possible.
emulate
是一个 zsh 内置命令。使用单个参数设置 zsh 选项以尽可能地模拟指定的 shell。
回答by lhunath
You can't "export" your .bashrc
to a .zshrc
. .bashrc
is a file that runs bash
commands. .zshrc
is a file that runs zsh
commands.
您不能“导出”.bashrc
到.zshrc
. .bashrc
是一个运行bash
命令的文件。 .zshrc
是一个运行zsh
命令的文件。
You can't expect zsh
to be able to run the bash
commands in your .bashrc
, so you should convert it into a new .zshrc
instead of trying to run .bashrc
from .zshrc
or copying the former into the latter.
你不能指望zsh
能够运行bash
在你的命令.bashrc
,所以你应该把它转换成一个新的.zshrc
,而不是试图运行.bashrc
从.zshrc
或复制前者到后者。
If you want a common shell initialization file for all your shells; use .profile
(and remove .bashrc
and .zshrc
). It's sourced by all POSIX shells. And in there, stick to POSIX shell features only. Then that code will run in any POSIX shell. (Though, I'm not 100% certain that zsh
is POSIX compliant).
如果您想要所有 shell 的通用 shell 初始化文件;使用.profile
(并删除.bashrc
和.zshrc
)。它来自所有 POSIX shell。在那里,仅坚持 POSIX shell 功能。然后该代码将在任何 POSIX shell 中运行。(不过,我不能 100% 确定它zsh
符合 POSIX 标准)。
See: http://mywiki.wooledge.org/DotFiles.
看: http://mywiki.wooledge.org/DotFiles。
Though - and I'd first misread this part of your question - you shouldn't experience errors from bash
when running your .bashrc
unless you put zsh
commands in there. Did you? What errors are you getting? Sounds to me like you've added zsh
code into your .bashrc
and bash
(obviously) doesn't understand.
虽然 - 我首先误读了您问题的这一部分 -除非您在其中放置命令,否则您bash
在运行时不应该遇到错误。你是否?你有什么错误?在我看来,您已将代码添加到您的并且(显然)不理解。.bashrc
zsh
zsh
.bashrc
bash
As an aside, ojblass
tries to make a point of portability which only partly succeeds. zsh
is a great shell (though I haven't had the honors myself), but when writing scripts; I'd recommend you do so with #!/usr/bin/env bash
instead. Mostly just for your own (and eventually, the people you share with their) sake of portability.
ojblass
顺便说一句,试图提出仅部分成功的可移植性点。 zsh
是一个很棒的外壳(虽然我自己没有获得荣誉),但是在编写脚本时;我建议你这样做#!/usr/bin/env bash
。主要是为了您自己(以及最终与您共享的人)的便携性。