Google-Compute-Engine

如何在 Google Compute Engine 上啟用 bash 補全?

  • October 9, 2020

我正在執行的計算實例是 Debian Buster。通常存在一個/etc/bash_completion文件。但是對於 GCE,它缺失了。他們甚至在預設情況下添加了一個部分~/.bashrc來引用它們都不存在的 bash 完成文件。

if ! shopt -oq posix; then
 if [ -f /usr/share/bash-completion/bash_completion ]; then
   . /usr/share/bash-completion/bash_completion
 elif [ -f /etc/bash_completion ]; then
   . /etc/bash_completion
 fi
fi

你是對的,它預設沒有安裝,我在自己的項目中嘗試過創建一個新的 Debian Buster VM 實例,/etc/bash_completion但不存在。

/etc$ ls -l bash_completion
ls: cannot access 'bash_completion': No such file or directory

只有在安裝 bash-completion 後,該 /etc/bash_completion文件才會出現。

sudo apt-get install bash-completion
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
 bash-completion
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 208 kB of archives.
After this operation, 1397 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main amd64 bash-completion all 1:2.8-6 [208 kB]
Fetched 208 kB in 0s (960 kB/s)     
Selecting previously unselected package bash-completion.
(Reading database ... 37801 files and directories currently installed.)
Preparing to unpack .../bash-completion_1%3a2.8-6_all.deb ...
Unpacking bash-completion (1:2.8-6) ...
Setting up bash-completion (1:2.8-6) ...
Processing triggers for man-db (2.8.5-2) ...

安裝後:

/etc$ ls -l bash_completion
-rw-r--r-- 1 root root 45 Feb 11  2019 bash_completion

引用自:https://serverfault.com/questions/1037110