[Top][All Lists]

[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 23:22:02 -0300

On Sat, Mar 17, 2018 at 2:06 PM, Chet Ramey <address@hidden> wrote:
> Processing the word argument to -W honors shell quoting, in order to
> provide a simple way to return words containing shell metacharacters and
> characters in $IFS. There is a sentence to this effect in the texinfo
> documentation, but that sentence is missing from the manual page.  I will
> add some clarifying text and make sure it appears in the man page.

I confess it took me quite a while to grasp what "honors shell quoting" meant
here, I think now I get it. The single quote in:

compgen -W "foo'bar aaa bbb"

opens up a single-quoted sequence (not sure what the formal, correct word
should be used here) which extends up to bbb, as if it were:

foo'bar aaa bbb'

Even though the sequence doesn't close with a single quote, it's
treated as such.
Then quote removal is applied, but there's nothing to be split on IFS, and
the final result of the splitting/expansion is the single word:

foobar aaa bbb

That's why completing "a" and "b" generates nothing, and "f" generates that

The man page does mention it:

"The string is first split using the characters in the IFS special
variable as delimiters.
Shell quoting is honored. Each word is then expanded using brace expansion,
tilde expansion, parameter and variable expansion, command substitution, and
arithmetic expansion, as described above under EXPANSION.  The results are split
using the rules described above under Word Splitting"

Perhaps it would be useful to expand "Shell quoting is honored" a bit,
quote removal. It bit me because I glanced over that sentence and
didn't analyze it more

This discussion has been most illuminating, I must say ! Thanks to
Chet and Clark !


reply via email to

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