/
do-test
109 lines (90 loc) · 1.88 KB
/
do-test
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/sh
#
# TODO: -G, -L, -N, -O, -S, -ef, -nt, -ot, -o, -v, -R, -z, -n, ==, =, !=, <, >, -eq, -ne, -lt, -le, -gt, -ge
#
test_file() {
echo
echo testing $1
if [ -a $1 ]; then
echo " File exists"
else
echo " File does not exist"
fi
if [ -b $1 ]; then
echo " Block special file"
else
echo " No block special file"
fi
if [ -c $1 ]; then
echo " Character special file"
else
echo " No character special file"
fi
if [ -d $1 ]; then
echo " Is a directory"
else
echo " Is not a directory"
fi
if [ -e $1 ]; then
echo " File exists"
else
echo " File does not exist"
fi
if [ -f $1 ]; then
echo " Regular file"
else
echo " No regular file"
fi
if [ -g $1 ]; then
echo " set-group-id bit is set"
else
echo " set-group-id bit is not set"
fi
if [ -h $1 ]; then
echo " File is symbolic link"
else
echo " File is not a symbolic link"
fi
if [ -k $1 ]; then
echo " Sticky bit is set"
else
echo " Sticky bit not set"
fi
if [ -p $1 ]; then
echo " Named pipe (FIFO)"
else
echo " No named pipe (FIFO)"
fi
if [ -r $1 ]; then
echo " File is readable"
else
echo " File is not readable"
fi
if [ -s $1 ]; then
echo " File size > 0"
else
echo " File size = 0 or file does not exist"
fi
if [ -t $1 ]; then
echo " File descriptor open and refers to terminal"
else
echo " File descriptor not open or not referring to terminal"
fi
if [ -u $1 ]; then
echo " set-user-id bit is set"
else
echo " set-user-id bit is not set"
fi
if [ -w $1 ]; then
echo " File is writable"
else
echo " File is not writeable"
fi
if [ -x $1 ]; then
echo " File is executable"
else
echo " File is not executable"
fi
}
test_file Conditional-Expressions
test_file $1