How can I set a user-specific environment variable that includes a space character?
export ENV_VAR="/Applications/Android Studio.app" should set the variable properly, but it's likely the program/script that uses the variable doesn't quote it properly. If if you can figure out what's using the variable, it might be possible to fix the script/program.

My first guess would be that the environment variable is used by a shell script that does something like:

somecommand $ENV_VAR/subdir/filename


The problem occurs because the shell will expand the variable, then perform word splitting -- that is, it will split /Applications/Android Studio.app/subdir/filename into two arguments: /Applications/Android and Studio.app/subdir/filename. Note that embedding escapes or quotes in the variable value doesn't do anything useful, because the shell processes quotes and escapes before performing variable substitutions. Thus, if you used export ENV_VAR="/Applications/Android\ Studio.app", it would be split into /Applications/Android\ and Studio.app/subdir/filename; if you used export ENV_VAR="'/Applications/Android Studio.app'" it would be split into '/Applications/Android and Studio.app/subdir/filename'.

The solution is to put double-quotes around the variable reference, like this:

somecommand "$ENV_VAR/subdir/filename"


which tells the shell not to perform word splitting after substitution, removing the problem.

Note that it's also possible that it's something other than a shell script, or a shell script that's doing something more complicated like using the variable to construct another variable, and possibly depending on word splitting when that variable is used.  Fixing this sort of usage can get messy.