How to Use ‘cd’ Command with Shell Variables Containing Spaces

bashcommand line

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.

Best Answer

You can use wildcards:

export temp="/Users/username/Dropbox??Personal?"

or:

export temp="/Users/username/Dropbox*Personal*"

Now, cd $temp should work.