I'd rather not parse STDERR, but I can't think of another way to tell the difference, programmatically, between the two:
$ ls /net/foo.example.com/bar/test
/net/foo.example.com/bar/test: Permission denied
$ ls /sdfsdf
/sdfsdf: No such file or directory
No matter what command I try, they both seem to return the same error code, so that's a dead-end:
$ ls /net/foo.example.com/bar/test
/net/foo.example.com/bar/test: Permission denied
$ echo $?
2
$ ls /sdfsdf
/sdfsdf: No such file or directory
$ echo $?
2
I've tried the various file tests in perl, but they both return the same codes as well.
Best Answer
Test the file instead.
See the
test
man page for other possibilities.