Redirecting Output

Redirect Output and Errors

1
$ command.sh > output.txt 2>&1

Using Permanent Redirection in Scripts

from: https://www.putorius.net/linux-io-file-descriptors-and-redirection.html

If you are writing a script and want to redirect data streams without appending the redirect operator or every line, you can use the exec command like this.

1
2
3
4
5
#!/bin/bash
# Redirect all stdout to output.txt
exec 1> output.txt
# Redirect all stderr to errors.txt
exec 2> errors.txt

You can use one, both or any number of custom file descriptors in your script.


comments powered by Disqus