Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

On the regular file.

已查看 6 次
跳至第一个未读帖子

Hongyi Zhao

未读,
2015年4月12日 02:57:002015/4/12
收件人
Hi all,

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; but I've tried the -f/-e for both a file and its symbolic link,
they will return true for both case.

So what's the meaning of `a regular file' in this context?

Regards
--
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.

Janis Papanagnou

未读,
2015年4月12日 03:18:232015/4/12
收件人
On 12.04.2015 08:56, Hongyi Zhao wrote:
> Hi all,
>
> 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; but I've tried the -f/-e for both a file and its symbolic link,
> they will return true for both case.
>
> So what's the meaning of `a regular file' in this context?

I interpret it as:
-e is a general test (that is true also for, e.g., directories)
-f there's a regular file behind that name (either directly or
indirectly through a link)."
-h/-L (not sure there is any difference between those two), but
this is a further specialization, specifically to test
symbolic links

So you have a test hierarchy (more generlized or more specialized):
-e
-f
-h
-L
-d
...


Janis

>
> Regards
>

Hongyi Zhao

未读,
2015年4月12日 03:59:082015/4/12
收件人
Thanks a lot for your hints.

It's my first time to know that the `-e' can test a directory. And I've
tried it and the result is *yes*!

Regards

>
>
> Janis

Thomas 'PointedEars' Lahn

未读,
2015年4月12日 06:49:412015/4/12
收件人
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.

Kaz Kylheku

未读,
2015年4月12日 09:57:072015/4/12
收件人
On 2015-04-12, Hongyi Zhao <hongy...@gmail.com> wrote:
> link; but I've tried the -f/-e for both a file and its symbolic link,
> they will return true for both case.
>
> So what's the meaning of `a regular file' in this context?

On my Ubuntu system, the man page goes on to say this:

"Except for -h and -L, all FILE-related tests dereference symbolic links."

Hongyi Zhao

未读,
2015年4月12日 10:00:132015/4/12
收件人
Thanks a lot for you notes.
0 个新帖子