当前位置: 首页 > 知识库问答 >
问题:

macos - Mac .zshrc 写入环境变量时被覆盖了如何恢复?

赫连淳
2023-05-11

题目描述

错误的使用了写入命令

export GOPATH=$HOME/go > .zshrc

导致我的.zshrc文件空了,不过我没有执行 source .zshrc,但是打开其他的终端我的命令已经失效了

期待的结果

恢复我的.zshrc

共有2个答案

马华茂
2023-05-11

vi ~/.zshrc, (不要sudo)

Swap file "~/.zshrc.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

选择:(R)ecover 恢复

或者看下 ~/.zshrc.swp 文件里面内容还在不在

公冶高义
2023-05-11

貌似无法恢复,你这样直接覆盖了。

至于source .zshrc仅仅是是否使当前.zshrc直接生效,并不会有啥影响。

你可以在其他未关闭的终端echo $PATH 看一下历史的路径


复制了一下我的供你参考

MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=/usr/local/mysql-5.7.16-osx10.11-x86_64/bin:$PATH
export PATH=/usr/local/Cellar/redis/3.2.6/bin:$PATH
export PATH=/usr/local/sbin:$PATH
export PATH=$HOME/.composer/vendor/bin:$PATH
#export PATH=/Users/lpe234/hadoop-2.7.3/bin:$PATH
#export HADOOP_HOME=/Users/lpe234/hadoop-2.7.3

# ANDROID_HOME
ANDROID_HOME=/Users/lpe234/Library/Android/sdk
export ANDROID_HOME
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

# jmeter
export PATH=$PATH:/Applications/apache-jmeter-5.4/bin

# Scala
export SCALA_HOME=/usr/local/opt/scala/idea

export HOMEBREW_GITHUB_API_TOKEN="8076c45f558ab76a21c6bca84b5aeb156b054cd4"

# flutter
export PATH=`pwd`/flutter/bin:$PATH

# Pods
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
# Go path
export GOROOT=/usr/local/Cellar/go/1.15/libexec
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN
export GO111MODULE=on
export GOPROXY=https://goproxy.io


export JIRA_HOME=/Users/lpe234/atlassian-jira-software-7.3.1-standalone/jira-home

# Path to your oh-my-zsh installation.
export ZSH=/Users/lpe234/.oh-my-zsh

# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git brew zsh-autosuggestions zsh-completions zsh-syntax-highlighting)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
export SSH_KEY_PATH="~/.ssh/rsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
alias cnpm="npm --registry=https://registry.npm.taobao.org \
--cache=$HOME/.npm/.cache/cnpm \
--disturl=https://npm.taobao.org/dist \
--userconfig=$HOME/.cnpmrc"
alias killtomcat="ps aux | grep tomcat | grep -v grep | awk '{ print $2 }' | xargs kill"

alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'

eval $(thefuck --alias)
export PATH="/usr/local/opt/cython/bin:$PATH"
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
export PATH="/usr/local/opt/curl/bin:$PATH"



export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
alias readlink=greadlink

export PATH="/usr/local/opt/curl/bin:$PATH"


alias confd=confd-0.16.0-darwin-amd64

alias cls=clear

alias fixusb="killall -STOP -c usbd"

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion







#export JAVA_HOME=/usr/libexec/java_home
#export JAVA_HOME=/Users/lpe234/.jenv/shims/
export PATH="/usr/local/opt/opencv@3/bin:$PATH"


export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

export PATH=/Users/lpe234/flutter/bin:$PATH


export PATH="/usr/local/opt/ruby/bin:$PATH"

export PATH="/Library/Apple/usr/bin/:$PATH"
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/opt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<
 类似资料:
  • 在for循环中,为不同的变量分配一个值。已经赋值的变量将从下一次迭代中获得赋值。最后,两个变量的值相同。该代码用于验证文件中的数据。当我打印这些值时,它会为第一次迭代打印正确的值,但在下一次迭代中,第一次迭代中指定的值会更改。当我在for循环中打印$value3和$value4的值时,它会为$value4显示null,为$value3显示一些值,但在下一次迭代中,$value3的值会被$value

  • 查看macOS 下环境 HomeBrew brew config HOMEBREW_VERSION: 2.4.16 ORIGIN: https://github.com/Homebrew/brew HEAD: 2a4c9f610e69b9fed1eec61ac2c53e4b11a32e4c Last commit: 3 months ago Core tap ORIGIN: https://gi

  • 问题内容: 我知道这个问题以前已经问过很多,但是我确实读过,我会告诉你我所得到的。 我将列出在 OS X Yosemite 10.10.1* 中执行的命令 * Java版本 java -fullversion 哪个java 未设置Java home变量,因为当我这样做时: echo $ java_home 或 echo $ JAVA_HOME 或 echo $ Java_Home 我在终端上什么也

  • 使用Helm模板,我可以指定部署环境变量。 但是,如果环境变量通过Openshift web console手动修改,那么即使模板代码发生了更改,它也会在升级时被Helm忽略。 模板/Deployment.yaml values.yaml 我如何使Helm在升级时总是覆盖环境变量?

  • 我需要我的应用程序应该从环境变量而不是应用程序中选择键的值。yml。 > 如果环境变量中不存在特定属性,则应从应用程序中选取值。yml,否则。

  • 我是新的macOS。我知道这个问题以前被问过很多,但是所有提到的方法都不适合我。我也试过https://www.youtube.com/watch?v=_gdpclEE-kA一个,但是它显示了一个错误,比如没有这样的文件或目录。