[linux]shell自动化版本控制

2016-6-14 写技术

中午“夜深人静”时分,写了个版本控制脚本,放在代码编译的开头,以后再也不用手动修改软件的版本号了,爽到没朋友有没有?

#!/bin/bash
tmp=`sed -n 's/.*VERSION.*"\(.*\)"/\1/p' version.h`
echo tmp

cnt=`echo $tmp | tr . "\n" | wc -l`

a=0;b=0;c=0

if [ $cnt == 3 ]; then
    a=`echo $tmp|sed -n 's/\(.*\)\.\(.*\)\.\(.*\)/\1/p'`
    b=`echo $tmp|sed -n 's/\(.*\)\.\(.*\)\.\(.*\)/\2/p'`
    c=`echo $tmp|sed -n 's/\(.*\)\.\(.*\)\.\(.*\)/\3/p'`
else
    b=`echo $tmp|sed -n 's/\(.*\)\.\(.*\)/\1/p'`
    c=`echo $tmp|sed -n 's/\(.*\)\.\(.*\)/\2/p'`
fi

echo verionName=$tmp
echo a=$a,b=$b,c=$c

sed -i 's/\(.*VERSION.*"\)[^"]*"/\1'$((a+0))'.'$((b+0))'.'$((c+1))'"/' version.h

x=`printf "%03d\n" $((a+0))`
y=`printf "%03d\n" $((b+0))`
z=`printf "%03d\n" $((c+1))`

标签: linux

发表评论:

Powered by anycle 湘ICP备15001973号-1