1

I've come across this question in an attempt to search for a way to inline expand my glob pattern in bash. But in my case the pattern contains some character class.

Let say I have 3 files:- abc bbc 1bc

When I input:

$> somecommand [[:alpha:]]bc

I would like to know is there any key combination that would expand my command inline as:

$> somecommand abc bbc

I've tried Ctrl+X * key sequence with no luck. It seems it's working only for a simple glob pattern but fails to expand when a pattern contains some character class like [[:alpha:]]

  • somecommand [a-zA-Z]bc? – Cyrus Nov 3 '18 at 11:03
  • @Cyrus Assuming that they use [[:alpha:]] because they know it may generate different results depending on the current locale, this may not be a general solution. – Kusalananda Nov 3 '18 at 11:19
  • I think it's down to : being considered as a word delimiter. See also ^X* on *:*. – Stéphane Chazelas Nov 3 '18 at 11:20
  • @Kusalananda: I had not fully understood the question. – Cyrus Nov 3 '18 at 11:22
1

That's because : is among the list of characters that readline considers as word delimiters for word completion (which bash exposes in the $COMP_WORDBREAKS shell variable).

After:

COMP_WORDBREAKS=${COMP_WORDBREAKS/:}

(to remove : from $COMP_WORDBREAKS), Ctrl+X* should work.

One might argue that : shouldn't be in that list in the first place for the very reason that it's used in character classes, but I suppose the rationale is that you want to be able to use completion on things like:

PATH=~/bin:/usr/locTab

And that mechanism is too crude (you'll notice that Ctrl+X* on 'a'* doesn't work either even if you remove ' from $COMP_WORDBREAKS) to accommodate both so it's a compromise. See zsh, a shell with much more advanced editing capabilities, that works in both cases here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.