find命令是:在linux的bash shell查找命令
find ./ \(-path dir_a -o -path dir_b \) -prune
我要转换为:
./find.sh dir_a dir_b
所以我的代码(在不工作):
function myfind() {
num=1
tmp=""
for i in [email protected]
do
tmp="$tmp -path './$i' "
if [ $((num++)) -ne $# ]
then
tmp="${tmp} -o"
fi
done
echo $tmp # this is ok!!
find ./ \($tmp \) -prune # is doesn't work, why???
}
请勿使用单个变量'tmp'请改用[array](http://mywiki.wooledge.org/BashGuide/Arrays)。在[此链接]中检查'quoting'中的最后一个代码片段(http://mywiki.wooledge.org/BashGuide/Practices#Quoting) – anishsane 2015-03-25 06:46:57
您使用'$ @'未加引号显然是错误的。它需要用双引号引起其特殊含义,与'$ *'(引用或不引用)不同。 – tripleee 2015-03-25 06:52:33