需要一些帮助来简化bash中的脚本

时间:2018-03-27 10:14:36

标签: bash

实际上,这是我的第一篇文章。 感谢任何可以提供帮助的人。

#!/bin/bash

for file in *
 do
  if [ -s $file ]; then
        continue
   else
        echo "$file is empty and will be removed"
        rm $file
  fi
 done
     for file in *
      do
       if [ -x $file -a -f $file ];then
          echo "$file is an executable"
       fi
      done

是否有更简单的方法来编写此脚本,以便将其全部用于1 for for循环?

1 个答案:

答案 0 :(得分:1)

试试这个:

#!/bin/bash

for file in *; do
  if [ -s "$file" ]; then 
      if [ -x "$file" -a -f "$file" ]; then
          echo "$file" "is an executable"
      fi
  else 
      echo "$file" "is empty and will be removed"
      rm "$file" 
  fi

done