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

Posted October 20, 2003 by Rex in Bourne shell scripting

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 ]
cat testfile
echo file is not readable

The Conversation

Follow the reactions below and share your own thoughts.