Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wall -Wno-parentheses -Wno-format-security uname output: Linux n16-118-182 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.0 Patch Level: 17 Release Status: release Description: I was develop a bash-completion function which can auto-complete history command. But when I use $ compgen -W "$(fc -l -10)" -- "${COMP_WORDS[1]}" It gave me a weird result. After many debug, I found that compgen will do command subtitution and parameter expansion in word list. It executed every $(...) in bash history so it gave a weird result. For example, this command $ compgen -W '`ls`' will display current dir's content. $ compgen -W '$HOME' will display the HOME dir instead of literal '$HOME' $ compgen -W 'HOME' -- 'H' will get HOME but $ compgen -W '$HOME' -- '$' will get nothing. Repeat-By: compgen -W "$(fc -l -10)" -- "${COMP_WORDS[1]}" compgen -W '`ls`' compgen -W '$HOME' compgen -W '$HOME' -- '$'