Linux 这个脚本做什么?

Linux 这个脚本做什么?,linux,bash,Linux,Bash,我不知道回答这类问题是否好,因为这是家庭作业。。。但我看到了其他被标记为家庭作业的问题得到了回答,所以我们开始吧 #!/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

我不知道回答这类问题是否好,因为这是家庭作业。。。但我看到了其他被标记为家庭作业的问题得到了回答,所以我们开始吧

#!/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
  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

请原谅,如果我不能回答这个问题。。。如果它是错误的,请删除它并提醒我不要再这样做。

它不会做任何人认为它会做的事;它正在抓取bug。它似乎试图运行/share及其子文件夹中的所有内容。这不可能是好事。它让你所有最疯狂的梦想成真。
#!/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