开发者

what does this script do?

#!/bin/bash
RYD=/share
FILESPEC=*.sh
DIRPERM=700
FILEPERM=750
OWNER=user:group
CH_FSPEC=0
if [ -d $RYD ]; then
  find $RYD -type d | xargs chmod $DIRPERM
  if [ $CH_FSPEC -gt 0 ]; then
    find $RYD -type f | xargs chmod $FILEPERM
 开发者_StackOverflow else
    find $RYD -type f | grep -v "$FILESPEC" | xargs chmod $FILEPERM
  fi
  chown -R $OWNER $RYD
  for SCRIPT in $RYD/$FILESPEC; do
    if [ -x $SCRIPT ]; then
      echo "Executing : $SCRIPT"
      . $SCRIPT
    fi
  done
else
  echo "ERROR! The directory doesn't exist."
  exit 1
fi
exit 0


I do not know if it's good to answer this type of questions, as it's homework... but I saw other questions tagged as homeworks that was answered, so here we go.

#!/bin/bash
RYD=/share
FILESPEC=*.sh
DIRPERM=700
FILEPERM=750
OWNER=user:group
CH_FSPEC=0
if [ -d $RYD ]; then # If $RYD is a directory
  find $RYD -type d | xargs chmod $DIRPERM # Look for all subdirectories and chmod them with $DIRPERM
  if [ $CH_FSPEC -gt 0 ]; then # if $CH_FSPEC > 0
    find $RYD -type f | xargs chmod $FILEPERM # find all files inside $RYD and chmod them with $FILEPERM
  else # if $CH_FSPEC <= 0
    find $RYD -type f | grep -v "$FILESPEC" | xargs chmod $FILEPERM # find all files inside $RYD, ommit *.sh files and chmod them with $FILEPERM
  fi
  chown -R $OWNER $RYD # chown $RYD with $OWNER
  for SCRIPT in $RYD/$FILESPEC; do # loop *.sh files inside $RYD
    if [ -x $SCRIPT ]; then # if they have exec perm
      echo "Executing : $SCRIPT" # run it
      . $SCRIPT
    fi
  done
else # if $RYD does not exist or isnt a directory
  echo "ERROR! The directory doesn't exist."
  exit 1
fi
exit 0

Please, sorry if I should not answer to this question... if it's wrong, please just delete it and alert me to not do it again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜