If I create a file as an unprivileged user, and change the permissions mode to
400, it's seen by that user as read-only, correctly:
$ touch somefile $ chmod 400 somefile $ [ -w somefile ] && echo rw || echo ro ro
All is well.
But then root comes along:
# [ -w somefile ] && echo rw || echo ro rw
What the heck? Sure, root can write to read-only files, but it shouldn't make a habit of it: Best Practice would tend to dictate that I should be able to test for the write permission bit, and if it's not, then it was set that way for a reason.
I guess I want to understand both why this is happening, and how can I get a false return code when testing a file that doesn't have the write bit set?