.bash_profile:分配错误

时间:2018-08-13 09:33:26

标签: bash macos

我正在Mac上为React native设置环境,我必须具有以下环境变量:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

所以我的.bash_profile文件看起来像这样(见下文);恐怕不同设置的PATH变量的定义会发生冲突。

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

# added by Anaconda3 4.3.0 installer
export PATH="//anaconda/bin:$PATH"

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

# Setting PATH for Flutter
export PATH = /Users/juliencorbin/flutter/bin:$PATH

# Setting path for Android home (react native tools) 
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools


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

此外,当我运行source $HOME/.bash_profile时,出现以下错误:

/Users/myname/.bash_profile:16: bad assignment

我应该如何处理所有这些PATH分配?特别适用于React native,这是我现在最想使用的版本。

1 个答案:

答案 0 :(得分:1)

此行中的错误:

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

使用IFS环境变量中列出的字符作为分隔符来重击splits each command line in words(默认分隔符为<space><tab><newline>)。第一个单词是要执行的命令,其余都是它的参数。

上面的行分为4个字。第一个单词是export,它接收3个自变量(PATH=/Users/juliencorbin/flutter/bin:...),而期望只有一个。

Bash命令和脚本中的分配不能不得在=运算符周围使用空格字符。错误行必须为:

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

=周围删除空格,并确保要分配给PATH的值中没有嵌入空格。如果您放置在其中的路径之一包含空格,则将整个右侧值都用引号("/Users/... ")包裹。