bash command completion tool bash-completion

What is a shell?

Simply understand that it is the intermediate medium used when the system interacts with the computer hardware. It is just a tool of the system. In fact, there is another layer between the shell and the computer hardware that is the system kernel.

For example, if the computer hardware is compared to a person's body, and the system kernel is the human brain, as for the shell, it seems more appropriate to compare it to the human facial features.

Back on the computer, the user directly faces the shell instead of the computer hardware. The user tells the shell the instructions, and then the shell transmits to the system kernel. The kernel then controls the computer hardware to perform various operations.

Bash is the command line terminal under the linux environment. It can automatically complete commands and paths. Bash-completion is an enhancement to the bash completion function, adding the completion of parameters and package names;

Simple understanding: [Bash introduction & how Bash processes commands]

 

Ubuntu environment installation [bash-completion]:

  • Confirm whether /etc/bash_completion exists, if not, install one;
apt install bash-completion

 After the installation is complete, a bash_completion file will appear in the /etc directory;

  • Run in the user's shell;
source /etc/bash_completion

 It can also be added to the configuration file;

  • Edit the file, vi /etc/bash.bashrc 

Cancel the # symbol comment of if elif above, as shown below:

# enable bash completion in interactive shells
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
  •  Switch bash interpreter again, #bash

At this time, enter the apt command and press the [tab] key, the display is as follows:

 

Automatic completion of bash in k8s environment:

  • Confirm whether /etc/bash_completion exists, if not, install one (same as above);
  • Import bash auto-completion commands;
source <(kubectl completion bash)
  • Switch the bash parser again, #bash

After the above operations have installed the dependent packages, re-enter the terminal to take effect, enter kubectl to view all commands, and press the [tab] key, the display is as follows:

 

prompt:

  • If everything is normal, you can use the automatic completion function of Tab;
  • If you still can't complete the Tab health, you can exit the command line, and then reopen the terminal; (recommended)
  • Or restart the system to start the software;

 

Guess you like

Origin blog.csdn.net/ChaITSimpleLove/article/details/109440590