$ DOCS="/cygdrive/c/Users/my\ dir/Documents"
Here's your first problem. This puts an actual backslash character into $DOCS
, as you can see by running this command:
$ echo "$DOCS"
/cygdrive/c/Users/my\ `
When defining DOCS
, you do need to escape the space character. You can quote the string (using either single or double quotes) or you can escape just the space character with a backslash. You can't do both. (On most Unix-like systems, you can have a backslash in a file or directory name, though it's not a good idea. On Cygwin or Windows, \
is a directory delimiter. But I'm going to assume the actual name of the directory is my dir
, not my\ dir
.)
$ cd $DOCS
This passes two arguments to cd
. The first is cygdrive/c/Users/my\
, and the second is dir/Documents
. It happens that cd
quietly ignores all but its first argument, which explains the error message:
-bash: cd: /cygdrive/c/Users/my\: No such file or directory
To set $DOCS
to the name of your Documents
directory, do any one of these:
$ DOCS="/cygdrive/c/Users/my dir/Documents"
$ DOCS='/cygdrive/c/Users/my dir/Documents'
$ DOCS=/cygdrive/c/Users/my\ dir/Documents
Once you've done that, to change to your Documents
directory, enclose the variable reference in double quotes (that's a good idea for any variable reference in bash, unless you're sure the value doesn't have any funny characters):
$ cd "$DOCS"
You might also consider giving that directory a name without any spaces in it -- though that can be hard to do in general on Windows.