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?
Variable names aren't case-sensitive, and can include spaces and special characters.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With