01
02
myPath=
"/var/log/httpd/"
03
myFile=
"/var /log/httpd/access.log"
04
05
if
[ ! -x
"$myPath"
];
then
06
mkdir
"$myPath"
07
fi
08
09
if
[ ! -d
"$myPath"
];
then
10
mkdir
"$myPath"
11
fi
12
13
14
if
[ ! -f
"$myFile"
];
then
15
touch
"$myFile"
16
fi
17
18
if
[ ! -n
"$myVar"
];
then
19
echo
"$myVar is empty"
20
exit
0
21
fi
22
23
24
if
[
"$var1"
=
"$var2"
];
then
25
echo
'$var1 eq $var2'
26
else
27
echo
'$var1 not eq $var2'
28
fi
29
-f 和-e的区别
30
31
Conditional Logic on Files
32
33
34
35
-a
file
exists.
36
37
-b
file
exists and is a block special
file
.
38
39
-c
file
exists and is a character special
file
.
40
41
-d
file
exists and is a directory.
42
43
-e
file
exists (just the same as -a).
44
45
-f
file
exists and is a regular
file
.
46
47
-g
file
exists and has its setgid(2) bit
set
.
48
49
-G
file
exists and has the same group ID as this process.
50
51
-k
file
exists and has its sticky bit
set
.
52
53
-L
file
exists and is a symbolic link.
54
55
-n string length is not zero.
56
57
-o Named option is
set
on.
58
59
-O
file
exists and is owned by the user ID of this process.
60
61
-p
file
exists and is a first
in
, first out (FIFO) special
file
or
62
63
named pipe.
64
65
-r
file
exists and is readable by the current process.
66
67
-s
file
exists and has a size greater than zero.
68
69
-S
file
exists and is a socket.
70
71
-t
file
descriptor number fildes is
open
and associated with a
72
73
terminal device.
74
75
-u
file
exists and has its setuid(2) bit
set
.
76
77
-w
file
exists and is writable by the current process.
78
79
-x
file
exists and is executable by the current process.
80
81
-z string length is zero.
82
83
84
85
是用 -s 还是用 -f 这个区别是很大的!