linux – How to make a script accept autocompletion in bash script?


Let's say I have a script that asks for user input as shown below.

Digite o caminho do arquivo:

How do I make this input autocomplete the path of directories in linux? I need this to avoid typos


The easiest way to do this is to add a shell script to /etc/bash_completion.d/. The basic structure of this file is a simple function that performs the completion and then the invocation of complete which is a bash compiler. Instead of going into details on how to use complete, I suggest you read an Introduction to Bash Completion . Part 1 covers the basics and Part 2 goes into how you would write a completion script.

Scroll to Top