Hongyi Zhao wrote:
> Then `man test' give the following notes:
>
> ---------------------------
> -e FILE
> FILE exists
> -f FILE
> FILE exists and is a regular file
> -h FILE
> FILE exists and is a symbolic link (same as -L)
> -L FILE
> FILE exists and is a symbolic link (same as -h)
> ----------------------------
>
> In the above description, -h/-L are used for justification a symbolic
> link;
_detection_, not justification
> but I've tried the -f/-e for both a file and its symbolic link,
> they will return true for both case.
No, the “test” command _exits with a status code of success_ in both cases,
most certainly 0 (as that is required by POSIX).
> So what's the meaning of `a regular file' in this context?
In Unix/POSIX, *everything* is a file – including directories. “Regular
files” are files that are neither ([symbolic] links to) directories nor
([symbolic] links to) special files (like *b*lock special files/devices such
as /dev/sda, and *c*haracter special files/devices such as /dev/null):
<
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_164>
You are getting the same result for a regular file and a symlink (symbolic
link) to it with “-f” because then test(1) resolves the symlink to the
regular file. On a symlink to a directory or /dev/null (character device),
my “test -f” (on Debian GNU/Linux, a Bash built-in) exits with status 1
(failure = “not a regular file”). This is POSIX-compliant behavior:
<
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html>
--
PointedEars
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.