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

Contributor Icon Contributed by Rex Date Icon October 20, 2003  
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

Previous recipe | Next recipe |
 
blog comments powered by Disqus