On 2/9/15 4:00 PM, Cheng Rk wrote:
>
>
> To [email protected]:
>
>
> According this documentation `help test`, I am expecting it should return
> false on anything other than a regular file,
>
> -f FILE True if file exists and is a regular file.
>
>
> but why it returned true on a symlink to a regular file?
>
> $ [ -f tmp/sym-link ] && echo true
> true
This is fundamental to how symbolic links work. Unless you test specially
for a symlink and use system calls like lstat and readlink to obtain
values, system calls that operate on filenames follow symbolic links
(open, stat, etc.).
The bash man page notes this:
"Unless otherwise specified, primaries that operate on files
follow symbolic links and operate on the target of the link, rather than
the link itself."
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/