Techno World Inc - The Best Technical Encyclopedia Online!

THE TECHNO CLUB [ TECHNOWORLDINC.COM ] => Shell Script => Topic started by: Mark David on March 16, 2007, 01:35:19 PM



Title: Determine if a file is readable by current Bourne shell script user
Post by: Mark David on March 16, 2007, 01:35:19 PM
Determine if a file is readable by current Bourne shell script user

A well constructed 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.

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