#!/bin/sh
arr=(
1
5
7
8
5
)
arrNew=(
1
2
0
5
7
)
# 创建存储查找结果的文件
creatFile(){
# 获取文件所在位置
filePtth="$( cd "$( dirname "$0" )" && pwd )"
echo "当前文件位置 $filePtth"
fireName="文件名"
allName="${filePtth}/${fireName}"
echo "完整路径 $allName"
if [ -f "$allName" ]
then
echo "删除旧的存档"
rm -rf "$allName"
else
echo "文件不存在"
fi
# 创建目录在当前的位置
# mkdir ${allName}
# 创建文件在当前的位置
# touch ${allName}
touch ${allName}
}
# 数据存储
functionAdd(){
inputText=$1;
# 去重逻辑
if [ `grep -c $inputText $allName` -eq 0 ];then
echo 'not have'
echo "add = $inputText"
if [ -f "$allName" ] ;
then
# 覆盖内容
# echo "$inputText" > "$allName"
# 添加内容
echo "$inputText" >> "$allName"
echo "================================" >> "$allName"
fi
fi
}
# 数组比较
findFunction(){
arr=$1
arrNew=$2
for(( i=0;i<${#arr[@]};i++)) do
first=${arr[i]}
for(( j=0;j<${#arrNew[@]};j++)) do
second=${arrNew[j]}
if [ "$first"x == "$second"x ];
then
# echo "add = $first"
# result[${#result[@]}]=$first
# result=("${result[@]}" $second)
# array_name=("${array_name[@]}" $second)
functionAdd $second
fi
done;
done;
}
creatFile
findFunction $arr $arrNew