Search code examples
bashbash-completion

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


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?


Solution

  • 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.