Bug in BSD: to whom shall I report it?
I found what I think is a bug in the command chown
in OS X 11.6. It appears to work contrary to its man page, ignoring the -f
flag.
T_MaceT 33 ) chown -f T_MaceT foo
chown: foo: No such file or directory
T_MaceT 34 ) echo $?
1
According to the man page, using -f
, it should ignore that the file doesn't exist nor should it change the return-value. (I have tested the correct behavior on RedHat 6 for comparison.)
I'm not sure who (if anyone) would fix these kinds of bugs. The man page refers to BSD. Is there an active project supporting these kinds of things?
It's not a bug, it's poorly written documentation. The -f
option for chown
states:
Don't report any failure to change file owner or group, nor modify the exit status to reflect such failures.
This means the -f
option is only applicable if the target file exists and there was an error in changing the owner or group of the file, which of course you can't do on a nonexistent file as in the OP example under macOS.
To show that the -f
option actually works as intended, use the following compound command in Terminal while not doing so as root
or using sudo
:
touch ${TMPDIR}testfile; chown root ${TMPDIR}testfile; echo $?; rm ${TMPDIR}testfile
The output will be, e.g.:
chown: /var/folders/7l/lcvbc47n3sd7jcztdhc9c_pw0000gn/T/testfile: Operation not permitted
1
In this first form, without the -f
option it fails, exits >0, because the chown
command is trying to set the owner of ${TMPDIR}testfile
to root
while being executed not as root
and not using sudo
.
Now execute with the -f
option:
touch ${TMPDIR}testfile; chown -f root ${TMPDIR}testfile; echo $?; rm ${TMPDIR}testfile
The output will be:
0
In this second form, with the -f
option, it succeeds, exits with 0 without having made any change, because it was done not as root
and not using sudo
, which is necessary to change the owner of a file to root
.
Note that each OSes chown
is not equal in all functionality to each other. In other words, while I don't have Red Hat, as mentioned in the OP, I do have Linux Mint to compare to, and the man page in Linux Mint -f
option for chown
states:
suppress most error messages
As you see most is the keyword, so it doesn't suppress all error messages in Linux Mint nor is the description of what -f
does with chown
under Linux Mint as detailed and explicit as under macOS.
So while in Linux Mint, not as root
or using sudo
, chown -f root non_existant_filename
will not output an error, however, its exit code is 1
, not 0
as it is with the macOS chown
example above using -f
within its defined context.