3

Does bash/readline have a binding or a function that a key combination can be binded to in order to expand in-line braces? Similar to the way M-* key combination can be used for in-line globbing expansion.

So upon performing a key-combination

$ {a..z}

will turn in place into :

$ a b c d e f g h i j k l m n o p q r s t u v w x y z

1 Answer 1

7
$ $(echo {a..z})

CTRL + ALT + e

$ a b c d e f g h i j k l m n o p q r s t u v w x y z

Note that it will expand all the expansions on the command line. No matter where the cursor is placed.
With this command (and a=this; b=that):

$ echo "$a"; $(echo {a..m}); echo "$b"

This will be expanded:

$ echo this; a b c d e f g h i j k l m ; echo that

From man bash:

shell-expand-line (M-C-e)
Expand the line as the shell does. This performs alias and history expansion as well as all of the shell word expansions. See HISTORY EXPANSION below for a description of history expansion.

6
  • 1
    Under what circumstances is this supposed to work? I can't reproduce it with bash in Emacs command line editing mode in a tmux session, for example, or on macOS.
    – Kusalananda
    Commented Sep 11, 2018 at 7:01
  • Make sure that you have the ``` ` ` ``` (or $(...)). Search in man bash for shell-expand-line (M-C-e) @Kusalananda
    – user232326
    Commented Sep 11, 2018 at 11:55
  • @Isaac Oh well, maybe the default bash on macOS is too old and the most recent bash on OpenBSD is wrongly configured or something, or something else (in the desktop environment) is highjacking the keystrokes. Because it ain't working. That's why I was interested in the circumstances under which this is supposed to work.
    – Kusalananda
    Commented Sep 11, 2018 at 12:05
  • @Kusalananda For the keybinding : See what bind -p | grep shell-expand-line gives you. For the brace expansion: did you try doing it with two grave accent characters instead of a dollar-and-parentheses? the latter is a recent update to bash, an enter should expand it too. Tell us your bash --version
    – elig
    Commented Sep 23, 2018 at 4:27
  • 1
    It did not work for me, but as it turns out you can't do it in vi mode (set -o vi). After unsetting vi mode, it worked fine.
    – Quasímodo
    Commented May 29, 2020 at 20:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .