2016-01-28 23 views
0

我在詹金斯看起来像各种工作Repo_URLs:shell脚本中提取的应用程序名称

ssh://[email protected]:7999/sad/agreement-edge.git 
ssh://[email protected]:7999/che/agreement-middle.git 
ssh://[email protected]:7999/char/login-edge.git 

我需要提取协议边缘,协议中间人,从中登录边缘

比方说,回购URL被设置为可变

RepoEndpoint = SSH://[email protected]:7999 /悲伤/协议-edge.git

我如何提取协议边缘呢?

+0

随着SED:'回声 “$ RepoEndpoint” | sed's |。*/||; s | \ .. * ||'' – Cyrus

回答

5

使用bash的Parameter Expansion

RepoEndpoint="ssh://[email protected]:7999/sad/agreement-edge.git" 
RepoEndpoint="${RepoEndpoint%.*}" 
RepoEndpoint="${RepoEndpoint##*/}" 
echo "$RepoEndpoint" 

输出:

 
agreement-edge 
+0

最后我不需要.git – Jeel

2

sed版本,你可以在文件上运行(如果你有多个行处理):

sed 's=.*/\(.*\).git$=\1=' file_name 

或直接在字符串上:

sed 's=.*/\(.*\).git$=\1=' <<< 'ssh://[email protected]:7999/sad/agreement-edge.git' 

...或者一个变量:

sed 's=.*/\(.*\).git$=\1=' <<< "$RepoEndPoint"