[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
test -t
From: |
jidanni |
Subject: |
test -t |
Date: |
Wed, 03 Sep 2008 23:08:23 +0800 |
On (info "(coreutils)File type tests", and test(1) man page, we see
`-t FD'
True if FD is a file descriptor that is associated with a terminal.
Well please mention what happens if FD is omitted:
$ test -t
The answer is it always returns true, no matter what. Test with
$ echo 'set -x; for i in 0 1 2 3 ""; do /usr/bin/test -t $i; : $?; done;
tty'|at now; sleep 4; mail
Same problem with the bash and dash builtin tests and documents.
bash is even more freaky:
$ t=test #bash builtin
$ $t -t; echo $?
0
$ $t -t ''; echo $?
1
$ $t -t ' '; echo $?
0
$ t=/usr/bin/test
$ $t -t; echo $?
0
$ $t -t ''; echo $?
/usr/bin/test: invalid integer `'
2
$ dash
$ t=test
$ $t -t; echo $?
0
$ $t -t ''; echo $?
test: 3: Illegal number:
2