A minus (a.k.a. dash) alone is not an option, but an operand (i.e. an argument that isn't an option). Because of this, putting --
before it has no effect. The dash is an operand in cd -
and still an operand in cd -- -
. Like other standard utilities, cd
treats an operand as an operand regardless of whether there's --
before it.
The cd
command assigns a special meaning to the operand -
. Anything else is a directory to switch to. cd -- -a
switches to the directory called -a
, because -a
is not special as an operand and the --
prevents cd
from treating it as an option. This doesn't work for -
alone which isn't an option.
Putting quotes around -
isn't going to help, since that would eventually pass the operand -
anyway.
Your only recourse is therefore to find another way of expressing the same idea, i.e. another name for the same directory. Fortunately, there's an easy one: if you add ./
before a relative file name, it still means the same file. The ./
does make a difference which is irrelevant in our case: CDPATH
is not consulted when the directory name begins with /
, ./
or ../
. Thus:
cd ./-
Another way, since -
is a directory, is to add a /
after it. Adding a /
at the end of a file name ensures that the file is treated as a directory (in particular, the command will operate on the directory itself and not on the symlink if the file is a symbolic link to a directory), but otherwise makes no difference. Thus:
cd -- -/
Writing -/
is suggested by the completion code, by the way, but in bash it only actually works with --
before it, bash doesn't have a special case for cd -/
(zsh does).