From within a shell script (sh/bash), how can I tell what device or file name I am redirecting to?
For example, I have a shell script named script.sh.
I run the shell script and redirect STDOUT to a file named out.txt, and redirect STDERR to a file named err.txt.
So, that would look like this:
$ ./script.sh > out.txt 2> err.txt Now, from within the shell script, I can tell if STDOUT (or STDERR) is being redirected, or not:
if [ -t 1 ]; then... if [ ! -t 1 ]; then... but, once I know STDOUT (or STDERR) is being redirected, how can I tell where it is being rdirected to?