bash and readline: tab completion in a user input loop?
问题 I'm making a bash script which presents a command line to the user. The cli code is as this: #!/bin/bash cmd1() { echo $FUNCNAME: "$@" } cmd2() { echo $FUNCNAME: "$@" } cmdN() { echo $FUNCNAME: "$@" } __complete() { echo $allowed_commands } shopt -qs extglob fn_hide_prefix='__' allowed_commands="$(declare -f | sed -ne '/^'$fn_hide_prefix'.* ()/!s/ ().*//p' | tr '\n' ' ')" complete -D -W "this should output these words when you hit TAB" echo "waiting for commands" while read -ep"-> "; do