Re: test if stdout is connected to terminal

From: Alexis Huxley (ahuxley_at_gmx.net)
Date: 10/29/04


Date: Fri, 29 Oct 2004 13:54:23 +0200


> I need to test if stdout is connected to terminal. I know of 'tty -s'
> which does the same for stdin.
>
> Is there an equivalent to 'tty -s' for stdout?

[ -t 1 ]

Then use the return code. E.g.:

        if [ -t 1 ]; then
               echo "stdout is a terminal"
        fi

The '1' is the file handle you want to test. 0 is stdin, 1 is stdout,
2 is stderr.

Alexis