shell工程实践——带选项提取文件并处理

时间: 2018-4-16

# 本脚本实现:

 1、 带选项的操作 ;

 2、截取终端输出;


#!/bin/sh


S=3; L=15; M=80;  H=250;  N=1; l=1;  R=1;


while getopts "hS:L:M:H:N:l:R:" opt
do
        case $opt in
                h )  echo  "   Usage:";
                     echo  "  ./test_png.sh  -S x -L x -M x -H x -N x -l x -R x ";
                     exit 0  ;;
                S )  S=$OPTIND ;; 
                L )    L=$OPTIND ;;
                
                M )  M=$OPTIND ;;
                H ) H=$OPTIND ;;
                N )  N=$OPTIND ;;
                l ) l=$OPTIND ;;
                R ) R=$OPTIND ;;
                ? ) 
               
                 echo -n  "The test will use default arguments\n";;
                   
        esac
done
rm dat.txt 2> /dev/null


echo "Start deal the images ..."
ls  ./mlkk/old_image/*.png >> dat.txt


cat dat.txt | while read line  
do  
    png_file=${line##*old_image/};   ## 截取old_image/ 后的字符
    echo -n "start to deal *******> $png_file <*******\n"


   ./MSR_original -S$S -L$L -M$M -H$H -N$N -l$l -R$R ./mlkk/old_image/$png_file MSR_rgb  MSR_gray
  
   
    cp  MSR_gray  ./mlkk/new_image_gray/$png_file
    cp  MSR_rgb   ./mlkk/new_image_rgb/$png_file
   
     
done 


rm dat.txt


echo -n "Deal finished \n"






猜你喜欢

转载自blog.csdn.net/ljh618625/article/details/79967024