Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output of last shell command

Tags:

csh

Not until midway through a 3 hour build script, I'll remember that I want to see something at the beginning of the output after it's done. At this point I've exceeded the number of lines in my terminal so I can't scroll up to see it (or the beginning is hard to find). Of course I can be better about storing my output, but I've always been curious if this were possible.

In a linux shell, is it possible to return the output of the last command. I realize I could have piped it or sent the output to a file, but my requirement is to retrieve that output after the command has been run.

Using csh, but would hear about any shell.

like image 838
ack Avatar asked Jul 20 '10 02:07

ack


People also ask

What does the last command show?

The last command displays information about the last logged-in users. It's pretty convenient and handy when we need to track login activities or investigate a possible security breach. The last command will, by default, take the system log file /var/log/wtmp as the data source to generate reports.

How do you get the last code out of exit command?

Extracting the elusive exit code To display the exit code for the last command you ran on the command line, use the following command: $ echo $? The displayed response contains no pomp or circumstance. It's simply a number.


2 Answers

No. The output of a program never passes through the shell's hands. Without redirection, it goes straight to the TTY. With redirection, it goes straight to whatever file or pipe it was directed to. The shell has no idea what the process sent to stdout/stderr.

like image 119
Nicholas Knight Avatar answered Sep 22 '22 20:09

Nicholas Knight


script(1) is exactly what you need:

script make exit vim typescript 

The script program will start a new shell and save input and output to the typescript file. When you're done, just close the shell with exit or ^D. If you'd rather not start a new shell but just run your build, you can use: script -c <command>.

like image 30
sarnold Avatar answered Sep 19 '22 20:09

sarnold