Determine if a file is readable by current Bourne shell script user

A well contructed shell script, like any good program, should handle error conditions gracefully. Checking if a file is readable before attempting to read it allows a script to branch instead of abort or display an error message.


if [ -r testfile ]
then
cat testfile
else
echo file is not readable
fi

The Conversation

Follow the reactions below and share your own thoughts.