0

If I enter a command that runs for a long time or produce a lot of output, I often want to process that output in some way, but I don't want to re-run the command. For example, I might run

$ command
$ command | grep foo
$ command | grep foo | sort | uniq

But if command takes a long time, this is tedious to re-run. Is there a way to have bash (or any other shell) save the output of the last command, similar to the Python REPL's _?. I am aware of tee, but I would rather have my shell do this automatically without having to use tee all the time.

I am also aware I could store the output of a command, but again, I would like my shell to do this automatically, so I don't have to think about storing the command and I can just use my shell normally, and process the previous output when I want to.

1
  • 2
    No it doesn't remember the output of the previous command. It only gets sent to one place that you can decide or the default is stdout. Commented Jul 15, 2015 at 13:40

1 Answer 1

1

You can store the output into a variable:

output=$(command)
echo $output | grep foo
echo $output | grep foo | sort | uniq
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.