1. Shell checks whether a file or directory exists or has permissions
2 .#! /Bin/sh
3.
4. mypath = "/var/log/httpd /"
5. myfile = "/var/log/httpd/access. log"
6.
7. # Here, the-x parameter determines whether $ mypath exists and has executable permissions.
8. If [! -X "$ mypath"]; then
9. mkdir "$ mypath"
10. fi
11.
12. # Here, the-D parameter determines whether $ mypath exists.
13. If [! -D "$ mypath"]; then
14. mkdir "$ mypath"
15. fi
16.
17. # Here, the-F parameter determines whether $ myfile exists.
18. If [! -F "$ myfile"]; then
19. Touch "$ myfile"
20. fi
21.
22. # other parameters include-N, which determines whether a variable has a value.
23. If [! -N "$ myvar"]; then
24. Echo "$ myvar is empty"
25. Exit 0
26. fi
27.
28. # determine whether two variables are equal
29. If ["$ var1" = "$ var2"]; then
30. Echo '$ var1 EQ $ var2'
31. Else
32. Echo '$ var1 not EQ $ var2'
33. fi
-F and-e
Conditional logic on files
-A file exists.
-B file exists and is a block special file.
-C file exists and is a character special file.
-D file exists and is a directory.
-E file exists (just the same as-).
-F file exists and is a regular file.
-G file exists and has its setgid (2) bit set.
-G file exists and has the same group ID as this process.
-K file exists and has its sticky bit set.
-L file exists and is a symbolic link.
-N string length is not zero.
-O named option is set on.
-O file exists and is owned by the user ID of this process.
-P file exists and is a first in, first out (FIFO) special file or
Named Pipe.
-R file exists and is readable by the current process.
-S file exists and has a size greater than zero.
-S file exists and is a socket.
-T file descriptor number Fildes is open and associated with
Terminal device.
-U file exists and has its setuid (2) bit set.
-W file exists and is writable by the current process.
-X file exists and is executable by the current process.
-Z string length is zero.
Whether to use-S or-F is very different!