Skip to content
Advertisement

Linux file descriptor – getting current redirection stdout file?

I’m trying to get the current stdout redirection, and having some trouble.

I have a script that is always run with stdout redirection ie:

JavaScript

In myscript.sh, I need to find out what file it is being output to.

I’m trying this currently (not working):

JavaScript

That’s outputting logfile = /tmp/sflq.r3f, for instance. I need to instead find that it’s going to /tmp/output.log

Is this even possible?

I’m using korn shell if it matters…

Thanks!

Advertisement

Answer

$() uses a pipe (or as it appears for ksh — a tempfile which ksh appears to use to emulate what usually is a pipe in other shells) to capture the output of readlink.

Inside $(), the stdout is that pipe (or tempfile in ksh’s case).

You can get around this interposed stdout file with something like:

JavaScript

Now:

JavaScript

should give you:

JavaScript

Another option is to think of a way avoid the variable altogether:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement