Here's a more comfortable way if you want use the cd commands to certain directories more often. It avoids writing the directory name every time.
In your .bashrc or .profile, insert:
# activate cdable_vars
shopt -s cdable_vars
# define shortcut for your directory, here DIR
export DIR="/Users/<username>/path/to/your/dir"
Execute your script once: . .bashrc
Then you can cd to your directory like this:
cd DIR
This should work even if the path contains spaces.
In shell scripting, however, you must quote the variable like this:
cd "$DIR"
Now: how do you place the path with the infix spaces into an env var so you can do
% cd $foo
? – Bogatyr – 2015-10-08T22:42:16.8536Just for the sake of completeness, you can also decide to quote just parts of the argument, like
cd /Users/niho/Desktop/"Reader 0.5"
or evencd /Users/niho/Desktop/Reader" "0.5
– user123444555621 – 2011-03-13T12:14:59.0433The last one (infix quotes) was new to me. Thank you! – joschi – 2011-03-13T17:07:42.793