Answers:
您可以使用相对路径或绝对路径来防止 - 单独站立并混淆bash的构建命令 cd:
mkdir ./-
cd ./-
对面 ~,由bash评估, - 是一个论据 cd。看看手册页(好吧,对于当前系统都在 man bash 如 cd 是内置的):
cd [-L|[-P [-e]]] [dir] Change the current directory to dir. [...] An argument of - is equivalent to $OLDPWD. [...]
关于波浪扩展的段落(简化为最常见的含义):
Tilde Expansion If a word begins with an unquoted tilde character (`~'), [...] the tilde-prefix is replaced with the home directory associated with the specified login name.
~ 在将参数传递给实际命令之前,将被bash替换。因此,以某种方式逃避它(例如使用 '~' 要么 \~ ) 将工作。 - 另一方面将传递给命令。转义没有用处:bash无论如何都不会对它进行评估,但它将作为单个字符串传递给未转义 cd,随后将开放 $OLDPWD。
Patrix更合理的开放方式,是一种更为深奥的替代品 - 文件夹将设置 $OLDPATH 至 -:
OLDPATH=- cd -