[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Feature request or advice on implementation for buffering command ou

From: Greg Wooledge
Subject: Re: Feature request or advice on implementation for buffering command output
Date: Wed, 27 Mar 2019 09:23:13 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Wed, Mar 27, 2019 at 12:49:45AM -0700, Anders Brujordet wrote:
> Usecase:
> You run a command, the output is displayed in your terminal. Now that you
> see the output, you would like to grab say an ID from this output. Instead
> of coping and pasting the output, I would like to be able to do something
> like:
> # grep 'the thing that you want' <<< ${COMMAND_OUTPUT} | ./some_script
> Where COMMAND_OUTPUT is the last n number of output lines from the previous
> command.
> Now, I've looked at several ways of implementing this is Bash. They all
> break in various ways, because it usually means pushing all output to a
> file/variable and then pushing it to stdout. Would it be feasible to have
> Bash tee off anything intended for stdout to a variable?

No.  When bash runs commands, bash does not "see" the output of those
commands unless you specifically go out of your way to make it do so.

The output of a command goes directly to a terminal (or a file, but let's
assume a terminal for the purposes of this argument).  It does not go
"through" bash on the way to the terminal.  Bash does not know whether
any output was written to the terminal at all, let alone how much output
was written, let alone what it was.

> Is there already some way of achieving this functionality?


> If not, could anyone give me some pointers as to where or how this could be
> implemented?

You would have to ask your terminal for the most recent output it has
received (or the output on the bottom 3 lines, or whatever).  How to do
this would be specific to your terminal.  If you're using screen or tmux,
then it might actually be possible, but I wouldn't know *how*.  You'd
need to ask a screen or tmux mailing list for help with that, if you can't
find it in the manuals.

If you are not using screen or tmux, then you might as well be chasing
an impossible dream.  It's *probably* impossible, or so impractical that
you will not do it unless you're insane.  In any case, the possibility
or feasibility of extracting already-written data from a terminal is
going to depend on the terminal.  Every terminal is special, as in
special needs.  No two are alike.

reply via email to

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