我想编写一个执行以下操作的 shell 脚本(zsh):
- 通过 Homebrew 安装 Anaconda。
- 将 conda 添加到 PATH 中
.zshrc
。 - 更新 conda 基础环境。
我想出了以下解决方案:
# Installing Anaconda
if [ ! -d /opt/homebrew/Caskroom/anaconda ]; then brew install --cask anaconda; fi
# This adds conda to your PATH in .zshrc and makes sure that you can now use conda and activate conda environments
/opt/homebrew/anaconda3/bin/conda init zsh
# Sourcing zshrc
exec zsh
# Update conda base environment
conda update -n base -c defaults conda
问题是,这exec zsh
会替换当前的 shell,因此 conda 更新不会发生。
有没有更好的办法解决这个问题?
答案1
为什么要使用exec zsh
?为什么不改用source ~/.zshrc
?像这样:
# Installing Anaconda
if [ ! -d /opt/homebrew/Caskroom/anaconda ]; then brew install --cask anaconda; fi
# This adds conda to your PATH in .zshrc and makes sure that you can now use conda and activate conda environments
/opt/homebrew/anaconda3/bin/conda init zsh
# Sourcing zshrc
source ~/.zshrc
# Update conda base environment
conda update -n base -c defaults conda