消除目录/文件循环中的文件

时间:2019-02-15 18:36:55

标签: regex bash loops

#! /bin/bash
# Script to add all scripts to the main one for dispersion to the right scripts
# Must be run in the sudo mode

if [-z $1] then                             # Set the dir to scan
    scpdir="/default-dir/";
elif
    scpdir=$1;
fi
slffil=$scpdir"thisbashfile.sh";                # Ignore this file
if [-z $2]    then                              # Set the target output file
    tgtfil=$scpdir"myoutfile";      # Ignore the target file
elif
    tgtfil=$2;
fi

for i in `ls $scpdir*.*`; do
    # Set iteration skips/continue for: '~', 'html', 'tar' $slffil, $tgtfil
    if [ "$i" == "$slffil" ]; then continue; fi
    if [ "$i" == "$tgtfil" ]; then continue; fi
    case "$i" in [*~] | [*.tar.*] | [*.html] | [*.list] | [*.deb] | [*DRBL])
        continue;;
    esac;
    echo "$i";
done

对于此目录中的~htmltar文件,我需要第三行“ IF”行。我应该为此使用正则表达式,还是有另一种简单的方法从目录扫描中删除这些文件?

0 个答案:

没有答案