How do I place stdout on edit line?

后端 未结 1 612
南旧
南旧 2020-12-10 22:19

This is bash 5. I want the output of a command or pipeline to end up on the edit line.

$ perl -E\'say \"hi\"; say \"more lines\";\'
hi
more lines
$ perl -E\'         


        
1条回答
  •  北海茫月
    2020-12-10 22:43

    Ctrl+Alt+e expands command substitutions ($() and ``). It also replaces other kinds of expressions in your command prompt, e.g. aliases, see resources below for more details.

    In my experience it is a very useful and little known feature of Bash.

    You can use `` and Ctrl+Alt+e to replace a command line with its output. It doesn't preserve newlines, though. Also be careful with the side effects of anything you expand on your command line prompt. If you expand an `rm filename`, it will remove filename when you use Ctrl+Alt+e.


    Example:

    $ `perl -E'say "hi"; say "more lines";'`
    

    Ctrl+Alt+e

    $ hi more lines
    

    If the shortcut doesn't work for you, try Esc, then Ctrl+e. It has the same effect. You have to do it this way e.g. in the default Mac terminal.


    Resources:

    • Gnu.org Bash Reference Manual: 3.5.4 Command Substitution
    • Gnu.org Bash Reference Manual: 8.4.8 Some Miscellaneous Commands - Look for "shell-expand-line (M-C-e)".
    • Gnu.org Bash Reference Manual: 3.5 Shell Expansions
    • Superuser Stack Exchange: How to expand aliases inline in Bash?

    0 讨论(0)
提交回复
热议问题