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

Testing if a file is a terminal?



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?

Thanks again.



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