Add file/directory auto-completion to user input in Bash
The most common way to get input from a user in a Bash script is to use the read function like so:
However, this is not the best method to use when you want the user to input a directory path.
This is because pressing
tab enters a literal tab instead of auto-completing the directory path
like what happens in the terminal.
To add directory auto-completion to your bash script, all you have to do is add the
-e flag to the
read function like so: