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

Re: Testing if a file is a terminal?

On Tue, Dec 09, 2008 at 11:47:51AM -0500, Rocky Bernstein wrote:
> First, many thanks to Peter and Stéphane for the very informative
> answers on terminal redirection.
> Before allowing a terminal to be set, the zshdb debugger uses this test:
>     [[ -r "$1" && -w "$1" ]] && return 0 # Ok
> $1 is a string --  the device name (e.g. /dev/pts/1) -- not a file descriptor.
> But is this really the best one can do? I suppose on could also add a
> test if the device is a character device but I just wonder if there
> isn't a better way.
> isatty()  works on a file descriptor, but we don't have that yet. I
> suppose one could try to open that and then test but then care needs
> to be made to use that opened file descriptor and not say close and
> reopen that.
> Any other thoughts or suggestions?

You could compare the device major and type to that of $TTY
(using zstat). [ -t <fd> ] tests whether a fd is a terminal (in
any shell, not only zsh).

But why would you want to check for that?


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