我宁愿不解析STDERR,但我想不出另外一种方法来区分两者之间的差异:
$ls /net/foo.example.com/bar/test /net/foo.example.com/bar/test: Permission denied $ls /sdfsdf /sdfsdf: No such file or directory
无论我尝试什么命令,他们似乎都返回相同的错误代码,所以这是一个死胡同:
$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
改为测试文件.
原文链接:https://www.f2er.com/bash/385263.htmltest -e /etc/shadow && echo The file is there test -f /etc/shadow && echo The file is a file test -d /etc/shadow && echo Oops,that file is a directory test -r /etc/shadow && echo I can read the file test -w /etc/shadow && echo I can write the file
有关其他可能性,请参见测试手册页.