目标拿到svn的版本号作为打包的名称
svn info,先看一下svn的信息都有哪些
➜ svn info
Path: .
Working Copy Root Path: /Users/wuyutao/.jenkins/workspace/test/client/abc
URL: svn://192.168.8.1/test/client/abc
Relative URL: ^/client/abc
Repository Root: svn://192.168.8.1/abc
Repository UUID: db3bce81-f136-4b22-aeb7-036094440344
Revision: 9145
Node Kind: directory
Schedule: normal
Last Changed Author: Admin
Last Changed Rev: 9145
Last Changed Date: 2021-12-09 12:44:11 +0800 (四, 09 12 2021)
我想把Revision: 9145
,中的9145
,拿到作为包名abc_9145.apk
➜ svn info | grep Revision
Revision: 9145
怎么拿到9145
呢,于是网上一顿搜索bash正则替换
➜ svn info | grep Revision | sed "s/Revision: //g"
9145
成功拿到9145
,sed命令格式sed 's/oldValue/newValue/g'
,在这里我是吧字符串Revision:
替换成了空字符串。
然后放到一个变量中待用
➜ svn_ver=$(svn info | grep Revision | sed "s/Revision: //g")
➜ echo $svn_ver
9145
参考:
linux sed 正则提取字符串,Shell中使用grep、sed正则提取和替换字符串
https://blog.csdn.net/weixin_34500880/article/details/116578888
Shell中使用grep、sed正则提取和替换字符串
https://www.jb51.net/article/201958.htm