Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to set a shortcut so that I don't have to type a really long directory name so often. In ~/.bash_profile, I am doing something similar to:

export CDPATH=".:~:/This/Is/A/Really/Long/Path/That/Ends/With/My Name"

How do I escape/preserve the space in a directory name when trying to set this variable?

I've tried various solutions (using single quote vs double quote, escaping with a backslash (I even tried 'My\\\ Name'), no quotes at all, and combinations of those options).

Gracias.

share|improve this question
    
Did you try export CDPATH=".:~:'/This/Is/A/Really/Long/Path/That/Ends/With/My Name'"? –  August Karlstrom Mar 3 at 20:47
    
Have you tried if it works with directory without space? Maybe you should install bash-completion. Check out the end of my response (last edit). –  kaszynek Mar 4 at 9:20
1  
Also when you are trying check if $CDPATH is properly updated in your bash with echo $CDPATH. Don't forget to restart the console or directly source ~/.bash_profile. And try if it works with directory without space. Maybe there is something wrong with other settings. –  kaszynek Mar 4 at 9:28

1 Answer 1

up vote 1 down vote accepted
export CDPATH=".:~:/This/Is/A/Really/Long/Path/That/Ends/With/My Name"

should be fine

I've tried

cd /tmp/
mkdir "aaa bbb"
mkdir "aaa bbb/a" "aaa bbb/b"
export CDPATH="/tmp/aaa bbb"

and

cd a

works just fine

Also if you want to change directory faster you can create an alias

alias longpath="cd '/This/Is/A/Really/Long/Path/That/Ends/With/My Name'"

but it will not solve the problem of copying to that directory

cp longpath

won't work.

Maybe it is not working properly and you should install and enable bash-completion — it defines a _cd function and sets it as the completer for the cd command, which overrides the default completion and includes $CDPATH.

share|improve this answer
    
I swear I had tried that. I'll try again. I am on OS X Mavericks. Are you using Linux? Does that make a difference? –  joseph644 Mar 4 at 4:18
    
(In the mean time, I think the "alias longpath" suggestion would work nicely.) –  joseph644 Mar 4 at 4:19
    
Yes I'm using linux. I'm not sure if it makes the difference I think it shouldn't. –  kaszynek Mar 4 at 9:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.