How to add bash auto completion in RHEL 8 (Red Hat Linux)

I set up a new RHEL 8 VM from cloud images, but my auto-completion of bash shell commands are not working. How do I enable autocomplete feature in RHEL 8 (Red Hat Enterprise Linux 8)? How do I write simple bash completion code in RHEL 8?

Introduction: Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash can run most sh scripts without modification. bash-completion is a collection of shell functions that take advantage of the programmable completion feature of bash on RHEL 8. This page shows how to install and enable Bash auto completion in RHEL 8.

How to add bash auto completion in RHEL 8

The procedure is as follows to add bash completion in Red Hat Enterprise Linux 8:

  1. Open the terminal window/bash shell prompt
  2. Search for bash-completion on RHEL 8 by running: sudo yum search bash-completion
  3. Install programmable completion for bash on RHEL 8 by running: sudo yum install bash-completion
  4. Log out and log in to verify that bash auto completion in RHEL 8 working properly

Let us see all steps in details.

How to add bash completion RHEL 8

Bash completion is a useful tool for the automatically completing of file names, commands and more. Type the following yum command to install auto completion in RHEL 8:
$ sudo yum install bash-completion
$ sudo dnf install bash-completion

How to test programmable completion for Bash

Installer placed a shell script called /etc/profile.d/ You can view it with help of cat command:
$ cat /etc/profile.d/
Sample outputs:

# Check for interactive bash and that we haven't already been sourced.
if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_VERSINFO-}" ]; then
    # Check for recent enough version of bash.
    if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
       [ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
        [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
            . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
        if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
            # Source completion code.
            . /usr/share/bash-completion/bash_completion

How do I enable bash completion on RHEL 8 and use it from the current session

The above script will get call automatically from your login session or when you start a fresh shell session. For the current session use the source command to load it:
$ source /etc/profile.d/
Press the [TAB] key while typing a command to auto-complete syntax or options:
$ sudo yum i[TAB] $ cat /etc/re[TAB]

Writing your first simple bash completion code on RHEL 8

Say you always want to ping an IP address/host names of three servers using the ping command. So type the following at the shell prompt:
complete -W '' ping
Now type ping and press the [TAB] key to use any one of the domain names/IP address for ping command:
ping [TAB]


The easiest way to install bash completion software is to use a package manager such as yum command. You installed the bash-completion package and learned how to create simple function and wrappers on RHEL 8. For more info see this page.

This entry is 2 of 5 in the Linux / Unix Bash Auto Completion Tutorial series. Keep reading the rest of the series:
  1. Add bash auto completion in CentOS 8 Linux
  2. How to add bash auto completion in RHEL 8 (Red Hat Linux)
  3. RHEL / CentOS Linux install and activate Bash completion
  4. Ubuntu Linux add bash auto completion
  5. Fedora Linux install and enable Bash auto completion

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum