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

Contributor Icon Contributed by Rex  
Tag Icon Tagged: 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 ]
then
cat testfile
else
echo file is not readable
fi

 

No Comments -


No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment -