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: Paulo Marcel Coelho Aragão
Subject: Re: compgen -W doesn't split wordlist containing single quotes
Date: Sat, 17 Mar 2018 08:32:10 -0300

> 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'.

On Sat, Mar 17, 2018 at 7:51 AM, Paulo Marcel Coelho Aragão <
marcelpaulo@gmail.com> wrote:

> On Sat, Mar 17, 2018 at 12:16:24PM +0800, Clark Wang wrote:
>
> > This seems to work but it does not. For example in the command line
> >
> >   # some-cmd f<TAB>
> >
> > will become
> >
> >   # some-cmd foo'bar
> >
> > then you press ENTER and it'll still wait for another ' char.
>
> Oh, I hadn't realized that, you're right. My example was incomplete
> because when I realized that I had to sh-quote the words in wordlist, I
> used '-o filenames' in the comspec (I hit the original problem when I was
> completing filenames), which works:
>
> complete -o filenames -W "foo\'bar aaa bbb" some-cmd
>
> > 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.
>
> You're right: it does work ! Hey, thanks for pointing out the ${var@Q}
> syntax: I wasn't aware of it. Had a look at the man page, and realized I
> didn't know about the ${parameter@operator} syntax.
>
> This discussion was enlightening, thanks for that, Clark !
>
> Paulo
>


reply via email to

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