繁体   English   中英

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

[英]Interpolate variables in path (bash command line)

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

$A = ~/tmp/ t $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"

首先,您不希望在=两侧有任何空格。 其次,我对bash表现出上述方式没有任何问题。 尝试:

complete -r

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM