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

Wolkenarchitekt picture Wolkenarchitekt · Jan 27, 2011 · Viewed 15.8k times · Source

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?

Answer

miku picture miku · Jan 27, 2011

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.