Get autocompletion when invoking a "read" inside a Bash script

BashBash Completion

Bash Problem Overview


Inside my Bash script, I'm reading some variables entered by the user with read:

read -p "Glassfish Path:" GF_DIR

Now I want that the user gets a autocompletion when he has to enter a directory, like when you are on the Bash shell. So when he enters the first letters of a directory, he can autocomplete it by hitting TAB. Is that possible?

Bash Solutions


Solution 1 - Bash

Try:

read -e -p "Glassfish Path:" GF_DIR

-e enables readline:

 -e 
    If the standard input is coming from a terminal, Readline is used
    to obtain the line.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWolkenarchitektView Question on Stackoverflow
Solution 1 - BashmikuView Answer on Stackoverflow