如何获得“! -path"从文件中查找命令的参数 [英] How to get "! -path" argument from file for find command
问题描述
我需要一个脚本,可以在给定的路径上找到给定扩展名的文件,但不包括目录,它们的名字取自一个文件。
script.sh和一个white.list文件。
white.list包含:
/ path / something
$
/ path / someotherthing
脚本有:
whitelistfile = / scriptdir / white.list
whitelist =`cat $ whitelistfile`
if -n$ whitelist
然后
#在$ whitelist中收集listitem的白名单路径
;
do
excludepath + =!-path \$ {listitem} * \
完成
files =`find$ path$ excludepath -name *。$ 3-type f`
fi
echo $ files
问题是find不接受$ excludepath参数。有没有这样的目录。
有人可以帮我解决这个问题吗?
你会使用一个数组,正如我在你的其他问题。 Bash常见问题解答有一个关于从文件中读取行的事情。
所以:
whitelistfile = / scriptdir / white.list
,而IFS =读-r; do
excludepath + =(!-path$ REPLY)
done< $ whitelistfile
[[$ REPLY]]&& excludepath + =(!-path$ REPLY)
files =`find$ path$ {excludepath [@]}-name*。$ 3-type f`
I would need a script that can find files with the given extension on the given path, but excluding directories, their name taken from a file.
We have a script.sh and a white.list file. white.list contains:
/path/something
/path/someotherthing
Script has:
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
The problem is that find does not accept $excludepath argument. Says there is no such directory.
Can someone help me with this, please?
You'd use an array, as I explained in your other question. Bash FAQ has a thing about reading lines from a file.
so:
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`
这篇关于如何获得“! -path"从文件中查找命令的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!