Bug 227706

Summary: document that file(1) succeeds when the file doesn't exist
Product: Documentation Reporter: Yuri Victorovich <yuri>
Component: Manual PagesAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed Overcome By Events    
Severity: Affects Some People CC: 0mp, bcr, doc, lgfbsd
Priority: --- Keywords: easy, feature, needs-patch
Version: Latest   
Hardware: Any   
OS: Any   

Description Yuri Victorovich freebsd_committer freebsd_triage 2018-04-23 05:17:19 UTC
For nonexistent file file(1) returns zero on 11.1:
> $ /usr/bin/file /nonexistent
> /nonexistent: cannot open `/nonexistent' (No such file or directory)
> $ echo $?
> 0

Despite its manpage saying:
> RETURN CODE
>      file returns 0 on success, and non-zero on error.
Comment 1 lgfbsd 2018-04-23 14:37:53 UTC
I believe this is correct POSIX behavior:
"
    If the file named by the file operand does not exist, cannot be read, or the type of the file named by the file operand cannot be determined, this shall not be considered an error that affects the exit status.
"

An appropriate fix would be to add that text to our manual page.
Comment 2 Yuri Victorovich freebsd_committer freebsd_triage 2018-04-23 15:43:05 UTC
(In reply to lgfbsd from comment #1)

I agree.
Comment 3 Benedict Reuschling freebsd_committer freebsd_triage 2023-10-06 14:13:39 UTC
The EXIT STATUS section on current file(1) versions includes this:

EXIT STATUS
     file will exit with 0 if the operation was successful or >0 if an error
     was encountered.  The following errors cause diagnostic messages, but
     don't affect the program exit code (as POSIX requires), unless -E is
     specified:
           •   A file cannot be found
           •   There is no permission to read a file
           •   The file type cannot be determined

I think that covers the issue of this PR. Thanks for submitting it, it was fixed in the meantime. Sorry it took so long to close it.