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

Re: Testing if a file is a terminal?



On Tue, 9 Dec 2008 11:47:51 -0500
"Rocky Bernstein" <rocky.bernstein@xxxxxxxxx> 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?

(Let's see if StÃphane beats me.)

  [[ -t 0 ]] < $1

appears to do the right thing.  Obviously it fails if the file can't be
read, too, but that's surely OK.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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