0
It looks like sudo -n
on Mac OS X (10.10.3) always returns 0 as a return code.
So something like this will always show 0, regardless of whether the user has authenticated with his password first:
sudo -n true &> /dev/null ; echo $?
In the case that the user does not have a valid sudo session, I would expect to see 1 as an exit code, but on OS X, it always returns 0.
I'm asking since I've seen this pattern suggested to check for sudo access, e.g. here: https://superuser.com/a/587876/119764
What's the official (???) behavior of sudo -n
? Does it differ by version or OS, or am I missing something?
2My first reaction is "Of course behaviour may differ by OS." The GNU folks and the BSD folks are under no obligation to agree with each other. The "official" answer will have to be: check the man pages. – glenn jackman – 2015-04-17T15:59:34.997