Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set enviroment variable with having space mac

I want to set an environment variable that has space in it. it is a path to a folder and the folder name is:

/Applications/Android Studio.app/Contents/gradle/gradle-2.10

I edit .bash_profile and add the following line to it:

export GRADLE_HOME=/Applications/Android Studio.app/Contents/gradle/gradle-2.10

and I get the result

-bash: export: `Studio.app/Contents/gradle/gradle-2.10': not a valid identifier

what should I do?

like image 764
looooker Avatar asked May 20 '16 02:05

looooker


People also ask

Can environment variable names have spaces?

Variable names aren't case-sensitive, and can include spaces and special characters.

How do you handle spaces in file path OSX?

The solutions are to use quotes or the backslash escape character. The escape character is more convenient for single spaces, and quotes are better when there are multiple spaces in a path. You should not mix escaping and quotes.

Does Mac Have environment variables?

The shell uses environment variables to store information, such as the name of the current user, the name of the host computer, and the default paths to any commands.


1 Answers

You can do it either this

export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-2.10

way or this

export GRADLE_HOME="/Applications/Android Studio.app/Contents/gradle/gradle-2.10"

Important

Having taken so much pain in exporting the variable correctly, always make sure that you double quote the variable when you reference it in shell ie do:

"$GRADLE_HOME"

and not

$GRADLE_HOME

Example :

ls $GRADLE_HOME

will produce unexpected results.

like image 50
sjsam Avatar answered Oct 29 '22 00:10

sjsam