bash: any way to reuse the last output?

Ben Stringer ben at burbong.com
Fri Jan 23 13:52:01 UTC 2004


On Fri, 2004-01-23 at 17:46, Herculano de Lima Einloft Neto wrote:
> Mike Klinke wrote:
> > saveit find ....
> > saveit grep ....
> 
> Then I would have to type saveit everytime.. thanks for all your
> effort, but I'll be more exact as to what I really want: use bash
> just the way I always have, and when the _unexpected_ wish to
> manipulate the last output gets me by surprise, I will do, for instance:
> (say, with grep)
> 
> grep whatever $__
> 
> There.. wouldn't it be nice? :)

Okay - this has some problems, but if you really want this, you could
work around them.

Just roll your own output capture.

while read line
do 
  bash -c "$line" | tee /tmp/last.out1
  mv /tmp/last.out1 /tmp/last.out
done

This gives you the output of your last command in a fixed file
(/tmp/last.out). You can point a shell variable at that file if you
prefer the $_ notation - just need to make sure it is set at every pass
through the while loop. 

On the downside, you loose command history, search etc. etc.

It may be that a combination of using exec's redirection and a fifo may
make this cleaner - an interesting exercise :)

Cheers, Ben

-- 
.O.    Ben Stringer
..O    ben at burbong.com
OOO    linux|java|majitek|gnu





More information about the fedora-list mailing list