How to check a directory has a read/write permission

冷暖自知 提交于 2019-12-20 07:04:34

问题


I have a directory as shown

d-wx--x--x 2 bcheudev bcheudev  4096 Jun 18 06:16 test

which shows the directory does not have read permission.

But when i check the same through shell script it's giving result as dir test has read permission.

export IN_DIR=$MMHOME/test   
if [ -d ${IN_DIR}  ]    
then    
   if [ ! -r ${IN_DIR} ]    
   then    
      echo "${IN_DIR} Directory is not readable.">>$log_name    
      exit 255   
   fi    
else    
   echo "${IN_DIR} Directory does not Exists.">>$log_name
   exit 255    
fi

inside second if it's not going.

Please help


回答1:


Remember that root will always have read permissions.




回答2:


I think that your condition is incorrect. Try with :

if ! [[ -r ${IN_DIR} ]]
  then
    echo "${IN_DIR} Directory is not readable.">>$log_name
    exit 255
fi


来源:https://stackoverflow.com/questions/30930434/how-to-check-a-directory-has-a-read-write-permission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!