选项卡上的 Bash 变量扩展完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6418493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:13:41  来源:igfitidea点击:

Bash variable expansion on tab complete

bashreadlinebash-completion

提问by sholte

I'm running Ubuntu 11.04, and I'm seeing some odd behaviour when I try to use tab-completion in bash on a path that starts with a variable. If I've got TOP=/scratch, and I try to tab-complete:

我正在运行 Ubuntu 11.04,当我尝试在 bash 中以变量开头的路径上使用制表符完成时,我看到了一些奇怪的行为。如果我有 TOP=/scratch,并且我尝试制表符完成:

cd $TOP/foo

cd $顶/foo

it changes to:

它更改为:

cd \$TOP/foo

cd \$TOP/foo

I'd prefer it to complete to: cd $TOP/foobar or cd /scratch/foobar but I'd settle for it just not changing the line and requiring me to un-escape the $.

我更喜欢它完成: cd $TOP/foobar 或 cd /scratch/foobar 但我会满足于它只是不改变行并要求我取消转义 $。

Does anyone know where in bash/readline I should look to fix this?

有谁知道我应该在 bash/readline 的哪个位置解决这个问题?

回答by sehe

Found the bug report, please register (if not already registered) and add yourself to the 'people affected' list, I just did:

找到错误报告,请注册(如果尚未注册)并将自己添加到“受影响的人”列表中,我刚刚做了:

https://bugs.launchpad.net/ubuntu/+source/bash/+bug/778627

https://bugs.launchpad.net/ubuntu/+source/bash/+bug/778627

Workarounds

解决方法

Try enabling direxpandor cdable_vars:

尝试启用direxpandcdable_vars

shopt -s direxpand
# or
shopt -s cdable_vars

Apparently EscTabmight be a workaround:

显然EscTab可能是一种解决方法

I haven't found a proper solution to this, but there's a workaround. The escaping of environment variables can be disabled by pressing Esc followed by tab.

# cd $SO + [Esc] + [Tab]
# cd $SOME_DIR

我还没有找到合适的解决方案,但有一个解决方法。可以通过按 Esc 和 Tab 来禁用环境变量的转义。

# cd $SO + [Esc] + [Tab]
# cd $SOME_DIR


Confirm that as a bug! I just confirmed that the same thing works on

确认这是一个错误!我刚刚确认同样的事情适用于

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.10
Release:        10.10
Codename:       maverick

I get broken behaviour on (up-to-date) natty:

我在(最新的)整洁上有不良行为:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 11.04
Release:    11.04
Codename:   natty

Although I must add that I do notthe slash escaped, but the path (while valid, existing, accessible and readable) is not getting expanded.

尽管我必须补充一点,我没有将斜杠转义,但是路径(虽然有效、存在、可访问和可读)并没有得到扩展。

Info: https://help.ubuntu.com/community/ReportingBugs

信息:https: //help.ubuntu.com/community/ReportingBugs

回答by Kleag

The bug report refered to in other answers at bugs.launchpad.netgives a new workaround by issuing the command:

bugs.launchpad.net 的其他答案中提到的错误报告通过发出以下命令提供了一种新的解决方法:

shopt -s direxpand

It works for me.

这个对我有用。

回答by kgeter

I was having a similar problem in cygwin (NT-6.1 2.0.1 2015-04-30) bash (GNU 4.3.33), especially when I would try to tab-expand a path that contained spaces.

我在 cygwin (NT-6.1 2.0.1 2015-04-30) bash (GNU 4.3.33) 中遇到了类似的问题,尤其是当我尝试对包含空格的路径进行 Tab 扩展时。

I put shopt -s direxpandin my ~/.bashrc. Problem solved.

我把shopt -s direxpand我的 ~/.bashrc放进去。问题解决了。