The read command can use the -e option to use readline functionality. However, there appears to be a bug with auto-completion and read, which can be seen with:
Code:
$ cat complete.sh
#!/bin/bash
# set of URLs to match against
urls="http://example.com http://example.us http://example.net"
set -o emacs
bind 'set show-all-if-ambiguous on'
bind 'set completion-ignore-case on'
bind 'TAB:dynamic-complete-history'
# load bash's history list against which we'll attempt completion
for i in $urls ; do
history -s $i
done
read -e -p "URL? " word
echo Value read: $word
If you run complete.sh and hit the TAB key, you'll see partial completion of the URL list specified in $urls. Once that partial completion is done, bash no longer continues working on completion from that point. The good news is that Control-P/Control-N and arrow keys work to cycle through the list.
Another possibility, which you'll have to work out, is to read only 1 character at a time, and test for the TAB character. When you read TAB, you perform your own completion of the current input against your word list using compgen (eg. compgen -W "$urls" $current_input_word). You do this until you get only 1 exact match from compgen. With this mechanism, you'll also have to handle moving the cursor back to the beginning of the line (use tputs).