Answers:
您无需检查它是否存在,检查读写权限就足够了:
从中help test
选择相关测试:
-a FILE True if file exists.
-e FILE True if file exists.
-f FILE True if file exists and is a regular file.
-r FILE True if file is readable by you.
-s FILE True if file exists and is not empty.
-w FILE True if the file is writable by you.
因此,您可以尝试:
FILE="/path/to/some/file"
if [[ -r $FILE && -w $FILE ]]
then
# do stuff
else
# file is either not readable or writable or both
fi
if [[ -r $FILE ]] && [[ -w $FILE ]]
代替if [[ -r $FILE && -w $FILE ]]
吗?
-r
和-w
运算符