Does [ -f FILE ] have a bug on testing a symlink ?
To bug-bash@gnu.org: According this documentation `help test`, I am expecting it should return false on anything other than a regular file, -f FILETrue 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
Re: Does [ -f FILE ] have a bug on testing a symlink ?
On Monday, February 9, 2015 1:59 PM, Andreas Schwab wrote: >> According this documentation `help test`, I am expecting it should return >> false on anything other than a regular file, >> >> -f FILETrue if file exists and is a regular file. >> >> >> but why it returned true on a symlink to a regular file? > (bash) Bash Conditional Expressions:: Unless otherwise specified, primaries that operate on files follow symbolic links and operate on the target of the link, rather than the link itself. > Andreas. Then the builtin test help need a documentation fix, right? For some purpose, I need to make sure the file is regular (like for creating archives); will have to do something like this? [ -f tmp/sym-link ] && { [ -h tmp/sym-link ] && echo do something to break the symlink } do something to break link
Re: Does [ -f FILE ] have a bug on testing a symlink ?
On Monday, February 9, 2015 3:13 PM, Andreas Schwab wrote: Cheng Rk writes: >> Then the builtin test help need a documentation fix, right? You're addressing different lines but I am saying this line is inaccurate, right? -f FILETrue if file exists and is a regular file. Is there really a simple regular file test existing? > test: test [expr] Evaluate conditional expression. Exits with a status of 0 (true) or 1 (false) depending on the evaluation of EXPR. Expressions may be unary or binary. Unary expressions are often used to examine the status of a file. There are string operators and numeric comparison operators as well. The behavior of test depends on the number of arguments. Read the bash manual page for the complete specification.