Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
770 views
in Technique[技术] by (71.8m points)

bash - How do I place stdout on edit line?

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'say "hi"; say "more lines";' | ???magic-goes-here???
$ hi
> more lines
> █

or perhaps

$ hi more lines█
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...