2016-01-13 71 views
0

我需要一个脚本,该脚本可以在给定路径中查找具有给定扩展名的文件,但不包括目录,它们的名称取自文件。如何获得查找命令文件中的“!-path”参数

我们有一个script.sh和一个white.list文件。 white.list包含:

/path/something

/path/someotherthing

脚本:

whitelistfile=/scriptdir/white.list 
whitelist=`cat $whitelistfile` 

if test -n "$whitelist" 
then 
    # collect whitelist paths 
    for listitem in $whitelist; 
    do 
     excludepath+="! -path \"${listitem}*\" " 
    done 

files=`find "$path" $excludepath -name *."$3" -type f` 

fi 

echo $files 

的问题是,发现不接受$ EXCLUDEPATH说法。说没有这样的目录。

有人可以帮我解决这个问题吗?

回答

0

您会使用一个数组,如我在your other question中所解释的。 Bash FAQ有一个关于从文件中读取行的内容。

这样:

whitelistfile=/scriptdir/white.list 

while IFS= read -r; do 
    excludepath+=(! -path "$REPLY") 
done <$whitelistfile 
[[ $REPLY ]] && excludepath+=(! -path "$REPLY") 

files=`find "$path" "${excludepath[@]}" -name "*.$3" -type f` 
相关问题