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 <
address@hidden> wrote:

> > Actually every word in the -W "wordlist" needs to be sh-quoted twice
> (with
> > ``printf %q'' or the new address@hidden'' syntax). It'll be a bit easier if
> you
> > use an array.
>
> On a second thought, sh-quoting twice with address@hidden won't work as 
> expected
> in this case, since it encloses the expanded value with single quotes, so
> that:
>
> address@hidden:~/tmp$ arr=(foo\'bar aaa bbb)
> address@hidden:~/tmp$ arr=(address@hidden)
> address@hidden:~/tmp$ arr=(address@hidden)
> address@hidden:~/tmp$ echo "${arr[*]}"
> ''\''foo'\''\'\'''\''bar'\''' ''\''aaa'\''' ''\''bbb'\'''
> address@hidden:~/tmp$ compgen -W "${arr[*]}" -- f
> address@hidden:~/tmp$
> address@hidden:~/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 address@hidden 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]