gpt4 book ai didi

linux - 在路径中插入变量(bash 命令行)

转载 作者:太空宇宙 更新时间:2023-11-04 09:43:45 25 4
gpt4 key购买 nike

请告诉我,我应该怎么做,才能在我键入时在 bash 命令行中插入变量名?

$A = ~/tmp/在 tmp 文件夹中,我有 tmp1 和 tmp2 文件夹。

我输入:cd $A<TAB>什么也没发生。如果我添加额外的/并输入 cd $A/tmp1 , 它会在末尾放置额外的空间 cd $A/tmp1<space> .

我想要以下行为: cd $A<TAB> =====> cd ~/tmp/<without additional space>


有什么建议吗?

最佳答案

你需要说:

shopt -s direxpand

现在说:

cd $A/TAB

(注意 TAB 之前的 /)将在不添加空格的情况下显示目录。

来自手册:

direxpand
If set, bash replaces directory names with the results
of word expansion when performing filename completion.
This changes the contents of the readline editing buf‐
fer. If not set, bash attempts to preserve what the
user typed.

此外,不要通过说来设置变量:

A="~/tmp"

A=~/tmp

A="${HOME}/tmp"

关于linux - 在路径中插入变量(bash 命令行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18657364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com