Jawaban:
Anda tidak perlu memeriksa apakah itu ada, cek untuk izin baca dan tulis sudah cukup:
Dari help test
, pilihan tes yang relevan:
-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.
Jadi, Anda dapat mencoba:
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 ]]
bukan if [[ -r $FILE && -w $FILE ]]
?
-r
dan-w
operator