bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: compgen -W doesn't split wordlist containing single quotes


From: Clark Wang
Subject: Re: compgen -W doesn't split wordlist containing single quotes
Date: Sat, 17 Mar 2018 22:31:36 +0800

On Sat, Mar 17, 2018 at 7:32 PM, Paulo Marcel Coelho Aragão <
marcelpaulo@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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]