0

I know you can use the last argument passed to last the last command by hitting Alt-.. Is there a similar binding to get the output of the last command, or in other words the last value printed to stdout?

These questions are closely related but are not focused an a binding:
bash: get last stdout
How do I reuse the last output from the command line?

Peregrino69
  • 2,417
mcp
  • 717
  • 1
    As https://unix.stackexchange.com/questions/9024/how-do-i-reuse-the-last-output-from-the-command-line explains, there's no way to do that. What do you want a binding for? For running the last command again and capturing its output (which may be different this time)? – Gilles 'SO- stop being evil' Sep 22 '21 at 15:11
  • No, there isn't. Can you explain what exactly you want to achieve? Someone's likely to have come up with a workaround :-) – Peregrino69 Sep 22 '21 at 15:22

1 Answers1

2

No, because while the shell is involved in setting up the input/output file descriptors of the programs it runs based on any redirections, it's not involved in the actual data that passes between the running process and the terminal or files or such.

You'd need to explicitly arrange some way of capturing the output of all commands in advance to be able to access it again. Or run the command again, if the output of a second invocation would be useful.

There are some hacks to doing that in How do I reuse the last output from the command line?

ilkkachu
  • 138,973