Sungju's Slow Life

Personal journal


Simple tip to redirect all results into a file.

Here is a simple shell that works for that.

#!/bin/bash

exec 1<&-
exec 2 shell_result.txt
exec 2>&1

ls -l
ls fake_data
echo "Done"

It will close standard output/error and open that file descriptors for the file shell_result.txt. As a result, all the following commands’ output will be redirected to the specified file.



Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: