Red Hat Bugzilla – Bug 548450
the file command returns zero exit code even in case of unexisting file being tested
Last modified: 2012-10-29 08:59:00 EDT
Description of problem: %SUMMARY Version-Release number of selected component (if applicable): file-4.17-15.el5_3.1 How reproducible: Always Steps to Reproduce: [root@localhost ~]# file this_file_does_not_exist this_file_does_not_exist: ERROR: cannot open `this_file_does_not_exist' (No such file or directory) [root@localhost ~]# echo $? 0 [root@localhost ~]# Actual results: Returns zero exitcode. Expected results: Should IMHO return some non-zero exitcode. Additional info:
This request was evaluated by Red Hat Product Management for inclusion, but this component is not scheduled to be updated in the current Red Hat Enterprise Linux release. If you would like this request to be reviewed for the next minor release, ask your support representative to set the next rhel-x.y flag to "?".
Created attachment 405246 [details] a patch a patch to return non-zero status when error occurs
got this answer from upstream while submitting patch: --------- Imagine the scenario where we have to classify many files. What should happen if one of them does not exist/cannot be read? According to: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html If file does not exist, cannot be read, or its file status could not be determined, the output shall indicate that the file was processed, but that its type could not be determined. So it is reallly not an error if something went wrong dealing with a particular file. "The output" means stdout to me. ---------- does this mean we are supposed to not use the patch and treat the whole thing as NOTABUG?
We should IMHO distinguish between situation when file does not exist or cannot be read, which should end up with a non-zero exitcode. Another thing is situation where the file utility can't determine the file type - in this case I would expect a "can not determine file type" message at stdout and zero exitcode.
This request was evaluated by Red Hat Product Management for inclusion in the current release of Red Hat Enterprise Linux. Because the affected component is not scheduled to be updated in the current release, Red Hat is unfortunately unable to address this request at this time. Red Hat invites you to ask your support representative to propose this request, if appropriate and relevant, in the next release of Red Hat Enterprise Linux.
This request was erroneously denied for the current release of Red Hat Enterprise Linux. The error has been fixed and this request has been re-proposed for the current release.
Technical note added. If any revisions are required, please edit the "Technical Notes" field accordingly. All revisions will be proofread by the Engineering Content Services team. New Contents: Cause: File exits with 0 exit code even some input files were not found. This behaviour is OK according to POSIX specification and have been documented in file man page.
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. http://rhn.redhat.com/errata/RHBA-2012-0201.html
Technical note updated. If any revisions are required, please edit the "Technical Notes" field accordingly. All revisions will be proofread by the Engineering Content Services team. Diffed Contents: @@ -1,3 +1 @@ -Cause: File exits with 0 exit code even some input files were not found. +The file utility can exit with the 0 exit code even if some input files have not been found. This behavior is correct; refer to the file(1) man page for more information.- -This behaviour is OK according to POSIX specification and have been documented in file man page.