On Sat, Mar 17, 2018 at 7:32 PM, Paulo Marcel Coelho Aragão < marcelpa...@gmail.com> wrote:
> > Actually every word in the -W "wordlist" needs to be sh-quoted twice > (with > > ``printf %q'' or the new ``${var@Q}'' syntax). It'll be a bit easier if > you > > use an array. > > On a second thought, sh-quoting twice with ${var@Q} won't work as expected > in this case, since it encloses the expanded value with single quotes, so > that: > > paulo@monk:~/tmp$ arr=(foo\'bar aaa bbb) > paulo@monk:~/tmp$ arr=(${arr[*]@Q}) > paulo@monk:~/tmp$ arr=(${arr[*]@Q}) > paulo@monk:~/tmp$ echo "${arr[*]}" > ''\''foo'\''\'\'''\''bar'\''' ''\''aaa'\''' ''\''bbb'\''' > paulo@monk:~/tmp$ compgen -W "${arr[*]}" -- f > paulo@monk:~/tmp$ > paulo@monk:~/tmp$ compgen -W "${arr[*]}" > 'foo'\''bar' > 'aaa' > 'bbb' > > To produce the desired result, it has to be your original solution, using > 'printf %q'. > Did not know it would break this. I'm still using ``printf %q'' for my auto-completion code. Yes ${var@Q} is not compatible with ``printf %q''. The following is what I've found: http://lists.gnu.org/archive/html/bug-bash/2017-10/msg00113.html http://lists.gnu.org/archive/html/bug-bash/2017-10/msg00111.html -clark