我正试图从Bash转移到zsh.
我将.bashrc直接放到我的.zshrc中,当我再次尝试使用Bash时,它会导致很多错误.
如何将.bashrc导出到.zshrc?
lhu*_*ath 27
你不能" 导出 "你.bashrc的.zshrc. .bashrc是一个运行bash命令的文件. .zshrc是一个运行zsh命令的文件.
您不能期望zsh能够bash在您的命令中运行命令.bashrc,因此您应该将其转换为新命令,.zshrc而不是尝试.bashrc从.zshrc前者运行或将前者复制到后者中.
如果你想要所有shell的公共shell初始化文件; 使用.profile(和删除.bashrc和.zshrc).它来自所有POSIX shell.而在那里,坚持POSIX Shell功能只.然后该代码将在任何POSIX shell中运行.(虽然,我不是100%肯定zsh是POSIX兼容的).
看到: http://mywiki.wooledge.org/DotFiles.
虽然 - 而且我首先误读了你问题的这一部分 - 除非你把命令放在那里,否则你不应该bash在运行时遇到错误.你是否?你得到了什么错误?听起来像你已经添加了代码并且(显然)不明白..bashrczshzsh.bashrcbash
另外,ojblass试图提出一个只能部分成功的便携性. zsh是一个伟大的外壳(虽然我自己没有荣誉),但在编写脚本时; 我建议你这样做#!/usr/bin/env bash.主要是为了您自己(最终,与您共享的人)的便携性.
小智 6
对我来说,Ryen 的回答很方便。但我做了一点小小的改变。我在用户目录( vim ~/.profile )的 .profile 中添加了所有别名命令。
alias gs='git status'
alias gp='git pull'
alias gph='git push'
alias gd='git diff | mate'
alias gau='git add --update'
alias gc='git commit -m'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcot='git checkout -t'
alias gcotb='git checkout --track -b'
alias glog='git log'
alias glogp='git log --pretty=format:"%h %s" --graph'
alias gfo='git fetch origin'
Run Code Online (Sandbox Code Playgroud)
然后,我在 bash 和 zsh shell 中添加了 source 命令。
在 bash shell 中(vim ~/.bashrc)
source ~/.profile
Run Code Online (Sandbox Code Playgroud)
在 zsh shell 中( vim ~/.zshrc )
source ~/.profile
Run Code Online (Sandbox Code Playgroud)
对于那些在~/.bash_aliases中定义别名的人
\n集中/使用别名的最简单方法是在 ~/.zshrc 中引用它们
\ngedit ~/.zshrc :
\n...并在末尾添加以下内容:
\n...\n# Alias definitions.\n# You may want to put all your additions into a separate file like\n# ~/.bash_aliases, instead of adding them here directly.\n# See /usr/share/doc/bash-doc/examples in the bash-doc package.\n \nif [ -f ~/.bash_aliases ]; then\n . ~/.bash_aliases\nfi\nRun Code Online (Sandbox Code Playgroud)\n完成后运行:
\nsource ~/.zshrc\nRun Code Online (Sandbox Code Playgroud)\n瞧\xc3\xa0...现在你已经在 bash 和 zsh 之间共享了别名。
\n| 归档时间: |
|
| 查看次数: |
54451 次 |
| 最近记录: |