[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: compgen -W [wordlist] will do command subtitution and parameter expa
From: |
Chet Ramey |
Subject: |
Re: compgen -W [wordlist] will do command subtitution and parameter expansion in wordlist |
Date: |
Thu, 3 Mar 2022 10:50:54 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 |
On 3/3/22 7:32 AM, ladyrick via Bug reports for the GNU Bourne Again SHell
wrote:
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.
You might have saved yourself some time by reading the documentation
instead of relying on your assumptions.
-W wordlist
The wordlist is split using the characters in the IFS
special variable as delimiters, and each resultant word
is expanded. Shell quoting is honored within wordlist,
in order to provide a mechanism for the words to contain
shell metacharacters or characters in the value of IFS.
The possible completions are the members of the resul-
tant list which match the word being completed.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/