Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Testing if a file is a terminal?



On Thu, Dec 11, 2008 at 1:17 PM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Dec 11, 12:33pm, Rocky Bernstein wrote:
> } Subject: Re: Testing if a file is a terminal?
> }
> } David Korn has weighed in on this with respect to ksh.
> }
> } Here is code along he lines he has suggested (my formatting and other
> } small changes which may have introduced bugs):
>
> This is almost exactly what I suggested,

Then without a doubt you are on par with David Korn ;-)

>  except I omitted the
>
>  exec {fd}<&-
>
> because you expressed concern about opening and then closing again
> the terminal device.

Yes, that was the original problem. I can and may rewrite the function
to be open_if_tty rather than is_tty.

> In fact, I might even suggest:
>
>            if [[ -t $fd  ]] ; then
>                r=0
>            else
>                exec {fd}<&-
>            fi
>

Good suggestion. If I rewrite is_tty as open_if_tty will probably use. Thanks.



Messages sorted by: Reverse Date, Date, Thread, Author