Cheng Rk wrote: > 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
Symlinks originated in BSD. GNU is implementing previously existing behavior. It is a BSD feature that migrated to System V and then to GNU and elsewhere. The behavior is now standardized by POSIX so that it will always be the same everywhere and it is possible to write portable scripts that behavior the same everywhere. The idea is that symlinks should be completely transparent and invisible to most applications. The idea is that when normal things are run they don't realize they are using a symlink. Behavior would be exactly the same as if it were a regular file system link. That is what is happening in your test case. The symlink references an existing file, is a regular file and exists, therefore the status is true. If you have an application that needs to know if something is a symlink then then you will need to test for that case explicitly. Since this is a question and not a bug in bash it would be better discussed in the help-b...@gnu.org mailing list instead. Please send future use discussion there. Thanks. Bob