This scripts can't work if 'Patch' info contains in specfile, so we
should pattern 'Patch' from the beginning of lines.
Also sort patch number first, then select the last one.
# no new patch
if [ -n "$newadd_patch" ]; then
# Find the insert line num
- line_num=$(grep Patch[0-9]* -r $spec -n|tail -1|cut -d':' -f1)
+ line_num=$(grep "^Patch[0-9]*" -r $spec -n|tail -1|cut -d':' -f1)
# No patch. Insert after Source
if [ -z "$line_num" ]; then
line_num=$(grep Source[0-9]* -r $spec -n|tail -1|cut -d':' -f1)
num=0
else
# The first patch number
- num=$(grep Patch[0-9]* $spec |tail -1|sed 's/Patch\([0-9]*\):.*/\1/')
+ num=$(grep "^Patch[0-9]*" $spec |sed 's/Patch\([0-9]*\):.*/\1/' |sort -n |tail -1)
num=$(expr $num + 1)
fi