How to use cd with shell variable containing spaces I am trying to create an environment variable for a path that is long, has a space, and syntax.

I tried the following:

export temp=/Users/username/Dropbox (Personal)


And added it to my .profile.

I also tried:

export temp='/Users/username/Dropbox (Personal)'
export temp="/Users/username/Dropbox (Personal)"
export temp=/Users/username/Dropbox\ \(Personal\)


None of the above work. My end goal is to type cd $temp or cp $temp.
Besides the first assignment, all three work in assigning the correct value to $temp. But due to the way bash parses the command line, you need to write

cd "$temp"


afterwards to make it work (which also means that it is a good idea to always use "$var" in shell scripts).

It might be easier in your case to make an alias with

alias cdtemp='cd "/Users/username/Dropbox (Personal)"'


for use with cd.

For cp you still need to add the "" though. To avoid this, either name your folders without using characters with special meaning to the shell or create a symlink with ln -s ~/"Dropbox (Personal)" ~/DP.