BASH Script to cd to directory with spaces in pathname

Posted by Rails Newbie on Stack Overflow See other posts from Stack Overflow or by Rails Newbie
Published on 2009-02-26T04:50:42Z Indexed on 2010/05/13 9:24 UTC
Read the original article Hit count: 194

Filed under:

Argggg. I've been struggling with this stupid problem for days and I can't find an answer.

I'm using BASH on Mac OS X and I'd like to create a simple executable script file that would change to another directory when it's run. However, the path to that directory has spaces in it. How the heck do you do this? This is what I have...

Name of file: cdcode

File contents: cd ~/My Code

Now granted, this isn't a long pathname, but my actual pathname is five directories deep and four of those directories have spaces in the path.

BTW, I've tried cd "~/My Code"

and cd "~/My\ Code"

and neither of these worked.

If you can help, THANKS! This is driving me crazy!!

© Stack Overflow or respective owner

Related posts about bash