2016-01-28 24 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"