如何在 bash 命令行上恢复 shell 变量的制表符完成?

Eri*_*ric 6 bash tab-completion

我一直将最近访问的目录设置为 shell 变量 d1、d2 等。

在古老的 Fedora 机器上,我可以输入类似的命令

$ cp $d1/

并且 shell 会将 $d1 替换为类似 /home/acctname/projects/blog/ 的文本,然后会向我显示 .../blog 的内容,就像您期望任何制表符完成一样。

现在,ubuntu wheezy/sid 和 fedora 16 都只是 \-escape '$',自然没有完成显示。

您可以在 OSX 终端窗口中看到这种行为。在 10.8 上,执行类似的操作

ls $HOME/ 看看我的意思。

是否有可以恢复旧行为的 bash shell 变量或选项?

man bash 表明这是一个错误:

   complete (TAB)
          Attempt  to  perform  completion  on  the  text  before  point.  Bash
          attempts completion treating the text as  a  variable  (if  the  text
          begins  with  $),  username (if the text begins with ~), hostname (if
          the text begins with @), or command (including aliases and functions)
          in  turn.   If none of these produces a match, filename completion is
          attempted.
Run Code Online (Sandbox Code Playgroud)

当令牌以“~”或字母开头时,我会得到上述完成。只是'$'-完成被破坏了。

小智 10

从 bash 4.2 开始,此行为受

shopt -s direxpand # enable
shopt -u direxpand # disable
Run Code Online (Sandbox Code Playgroud)

有关背景信息,请参阅http://www.mail-archive.com/bug-bash@gnu.org/msg11251.html