blob: 090da3de073ca51526b3314d791a891de31def0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# test / [: file types, string and numeric forms, error statuses.
: >f; mkdir d; ln -s f link; ln -s nowhere dangling; mkfifo fifo
for op in -e -f -d -h -L -p -s -b -c -S; do
for file in f d link dangling fifo /dev/null nope; do
# A directory's size is 0 on z/OS, and POSIX leaves the size of one
# to the system, so -s is only tested on files.
case $op/$file in -s/d) continue ;; esac
[ $op $file ] && printf '%s %s\n' "$op" "$file"
done
done
echo data >f
[ -s f ] && echo nonempty
[ f -ef link ] && echo same-file; [ f -ef d ] || echo different
: >old; sleep 1.1; : >new
[ new -nt old ] && echo newer; [ old -ot new ] && echo older
[ old -nt new ] || echo not-newer
test -t 0 </dev/null; echo "tty=$?"
test -t 99; echo "tty99=$?"
[ ]; echo "empty=$?"
[ "" ]; echo "nullstr=$?"
[ ! ]; echo "bang=$?"
[ ! "" ]; echo "not-null=$?"
[ -n ]; echo "one-arg-op=$?"
[ = = = ]; echo "eqeqeq=$?"
[ "(" = "(" ]; echo "paren-str=$?"
[ ! = ! ]; echo "bang-eq=$?"
[ -f = -f ]; echo "op-eq=$?"
[ a = a -a b = b ]; echo "and=$?"
[ a = b -o b = b ]; echo "or=$?"
[ ! a = b ]; echo "not=$?"
[ \( a = a \) ]; echo "paren=$?"
[ \( a = b -o c = c \) -a d = d ]; echo "group=$?"
[ ! \( a = a \) ]; echo "not-group=$?"
[ 5 -gt 3 -a 2 -lt 1 -o 7 -eq 7 ]; echo "prec=$?"
[ -5 -lt -3 ]; echo "neg=$?"
[ 007 -eq 7 ]; echo "leading-zero=$?"
[ a != b ]; echo "ne=$?"
[ -z "" -a -n x ]; echo "zn=$?"
[ a = a 2>/dev/null; echo "no-bracket=$?"
[ 1 -eq x ] 2>/dev/null; echo "bad-int=$?"
[ a b c d e ] 2>/dev/null; echo "junk=$?"
[ \( a = a ] 2>/dev/null; echo "no-close=$?"
[ -f ]; echo "lone-f=$?"
[ a -zz b ] 2>/dev/null; echo "bad-op=$?"
test; echo "test-empty=$?"
|