If you keep getting an error message “_get_comp_words_by_ref: command not found” when you try bash completion for custom command with completion script, it means the bash-completion package is not installed. Tab completion feature is used to automatically complete commands or suggest options when you press Tab.

Fix _get_comp_words_by_ref: command not found

A fix for “_get_comp_words_by_ref: command not found” is to install bash-completion package. The commands to run varies from one Linux distribution to another, depending on the package management tool you use.

Install bash-completion on CentOS / RHEL:

sudo yum -y install bash-completion

Install bash-completion on Fedora:

sudo dnf -y install bash-completion

Install bash-completion on Ubuntu / Debian

sudo apt install bash-completion

Install bash-completion on macOS:

brew install bash-completion

After installing bash-completion on your system. Logout of current session:

$ logout

Login back and source your completion script.

$ source /path/to/completion/script

If source command has been added to ~/.bashrc file, then just run:

$ source ~/.bashrc

Now try using tab completion. See example below.

$ oc  <TAB>
adm              cancel-build     delete           extract          logout           plugin           replace          serviceaccounts  
annotate         cluster-info     describe         get              logs             policy           rollback         set              
api-resources    completion       diff             idle             new-app          port-forward     rollout          start-build      
api-versions     config           edit             image            new-build        process          rsh              status           
apply            convert          ex               import-image     new-project      project          rsync            tag              
attach           cp               exec             kustomize        observe          projects         run              version          
auth             create           explain          label            options          proxy            scale            wait             
autoscale        debug            expose           login            patch            registry         secrets          whoami       

I hope this guide helped you to fix “_get_comp_words_by_ref: command not found” error on your Linux / macOS terminal.

How To Copy and Paste Text Content from Linux Terminal

Connect To VPN Server with Cisco AnyConnect from Linux Terminal

How To Connect To Bluetooth Device from Linux Terminal

How To Google Search from a Linux Terminal

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here