遇到的问题:进行了目录的字符串大小比较,结果在目录下生成了很多的新文件
解决方法:在>和<的比较符号前增加\转义
代码如下:
#/usr/bin/bash
cd /opt/scf/service/deploy/zztradelogic/lib
list=`ls`
for file in $list
do
eval $(ls|grep $file |awk -F"-" '{printf("name=%s;version=%s;jarname1=%s",$1,$2,$0)}')
#开始遍历现存的列表,然后进行对比,将重复的较小版本号的jar包删除
nowlist=`ls`
#echo $nowlist
for i in $nowlist
do
#eval $(ls|grep $file |awk -F"-" '{printf("name=%s;version=%s;jarname1=%s",$1,$2,$0)}')
eval $(ls|grep $i | awk -F"-" '{printf("name2=%s;version2=%s;jarname2=%s",$1,$2,$0)}')
if [ $name = $name2 ]
then
if [ "$version" \< "$version2" ]
then
echo "$jarname1 比较小,删除"
rm -f $jarname1
elif [ "$version" \> "$version2" ]
then
rm -f $jarname2
echo "$jarname1 比较大,删除较小的$jarname2"
fi
fi
done
list=`ls`
for file in $list
do
eval $(ls|grep $file |awk -F"-" '{printf("name=%s;version=%s;jarname1=%s",$1,$2,$0)}')
#开始遍历现存的列表,然后进行对比,将重复的较小版本号的jar包删除
nowlist=`ls`
#echo $nowlist
for i in $nowlist
do
#eval $(ls|grep $file |awk -F"-" '{printf("name=%s;version=%s;jarname1=%s",$1,$2,$0)}')
eval $(ls|grep $i | awk -F"-" '{printf("name2=%s;version2=%s;jarname2=%s",$1,$2,$0)}')
if [ $name = $name2 ]
then
if [ "$version" \< "$version2" ]
then
echo "$jarname1 比较小,删除"
rm -f $jarname1
elif [ "$version" \> "$version2" ]
then
rm -f $jarname2
echo "$jarname1 比较大,删除较小的$jarname2"
fi
fi
done
done