9

I'm setting up the environment for React native on my Mac, and I have to had these environment variables:

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

So my .bash_profile file looks like this (see below); I'm afraid the definition of the PATH variable of my different setup get in conflict.

# 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

Furthermore, when I run source $HOME/.bash_profile, I get the following error:

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

How am I supposed to deal with all those PATH assignment ? specially for React native which is the one I want to work with the most right now.

Uj Corb
  • 1,959
  • 4
  • 29
  • 56

1 Answers1

23

The error is in this line:

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

Bash splits each command line in words using the characters listed in the IFS environment variable as delimiters (the default delimiters are <space>, <tab> and <newline>). The first word is the command to execute, the rest of them are its arguments.

The line above is split in 4 words. The first word is export and it receives 3 arguments (PATH, = and /Users/juliencorbin/flutter/bin:...) while it expects only one.

The assignments in Bash commands and scripts must not have white space characters around the = operator. The errant line must be:

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

Remove the spaces from around = and make sure there are no spaces embedded in the value you want to assign to PATH. Wrap the entire right-hand side value in quotes ("/Users/... ") if one of the paths you put there contain spaces.

axiac
  • 68,258
  • 9
  • 99
  • 134
  • 1
    I didn't know that, very interesting and thank you very much for your help @axiac ! Hence I have a question: will my PATH variable be the right one for each of these stuff (Anaconda, Python, flutter, etc.) ? when I print `echo $PATH` I feel like I get an addition of all those paths: (see comment below) – Uj Corb Aug 13 '18 at 09:51
  • `/Users/juliencorbin/.nvm/versions/node/v8.0.0/bin:/Users/juliencorbin/flutter/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin://anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin://anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/opt/node@8/bin:/Users/juliencorbin/.yarn/bin:./bin:./node_modules/.bin:/usr/local/opt/rbenv/shims:/usr/local/opt/rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/usr/local/sbin` etc. plus the Android path (too long to paste everything) – Uj Corb Aug 13 '18 at 09:52
  • 1
    When you type in a terminal a command name without a path (f.e. `ls`), the shell searches each path listed in `$PATH` until it finds the command. It seems your `.bash_profile` is executed twice (or, somehow, some paths are added twice to the `PATH` variable). This is not a problem *per se*. – axiac Aug 13 '18 at 10:01
  • Allright. so that is perfect. exactly what I was looking for. thank you very much @axiac ! – Uj Corb Aug 13 '18 at 10:02