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.
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.
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.
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.
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>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With