Reputation: 11
I wrote the below script to make the user get to the directory that interesting. Now I want to check the permissions of the directory, and if the directory exists to check the reading options.
echo "Please enter your desire folder directory ( \yourfolders) ?: \c"
read yourfolder
echo
# **** Check if the directory exists ******************
# **** find out if file has write permission or not ***
# *****************************************************
[ -w $yourfolder ] && W="Write = yes" || W="Write = No"
# *****************************************************
# *** find out if file has excute permission or not ***
# *****************************************************
[ -x $yourfolder ] && X="Execute = yes" || X="Execute = No"
# *****************************************************
# **** find out if file has read permission or not ***
# *****************************************************
[ -r $yourfolder ] && R="Read = yes" || R="Read = No"
echo "$yourfolder Permissions"
echo "$W"
echo "$R"
echo "$X"
if
[! -d "$yourfolder" ]; then
echo "That directory exists and below you can see the directory and files: \c"
echo
cd $yourfolder
echo
ls -ltr
echo
pwd
echo "Thank you very much!!!"
elif
[ -r "$yourfolder" ]; then
echo "That directory exists but not available for reading"
exit
# **** if the directory doesn't exists ****
else
echo "That directory doesn't exists !!!"
echo "Thank you very much"
fi
exit;;
Now as you can see I check the permissions but I don't know how to make the if statement. The first if statement it provide you the directory asap. In the second if checks if the directory exists. But for the permissions, HOUSTON we have a problem. I need to provide me a message that the folder is not accessible because of the permission " that " Any ideas?
Upvotes: 1
Views: 167
Reputation: 5422
You may want to take a look into this page:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
[ -d FILE ] True if FILE exists and is a directory.
[ -e FILE ] True if FILE exists.
[ -r FILE ] True if FILE exists and is readable.
[ -w FILE ] True if FILE exists and is writable.
[ -x FILE ] True if FILE exists and is executable.
There's a test for that
I hope this helps!
Upvotes: 1