Shell 判断文件类型

#!/bin/sh                                                                                                                                                            

source_dir="./down-5"
target_dir="./document"

if [ -d $target_dir ];then
  echo "$target_dir is exist"
else
  `mkdir "$target_dir"`
  echo "mkdir $target_dir done."
fi


for i in $source_dir/*; do
  case "$i" in
    *.pdf)
      echo "then PDF name is $i"
      `cp $i $target_dir`;;
    *.doc)
      echo "then doc is $i"
      `cp $i $target_dir`;;
    *.docx)
      echo "then docx is $i"
      `cp $i $target_dir`;;
  esac
done

猜你喜欢

转载自a280606790.iteye.com/blog/1040089