[英]Shell script to extract app name
我在詹金斯(Jenkins)有Repo_URLs從事各種工作,如下所示:
ssh://git@stash.dev-company.net:7999/sad/agreement-edge.git
ssh://git@stash.dev-company.net:7999/che/agreement-middle.git
ssh://git@stash.dev-company.net:7999/char/login-edge.git
我需要從中提取協議邊緣,協議中間,登錄邊緣 。
假設回購網址設置為變量
RepoEndpoint = ssh://git@stash.dev-company.net:7999 / sad / agreement-edge.git
我如何從中提取協議邊緣?
隨着bash的參數擴展 :
RepoEndpoint="ssh://git@stash.dev-company.net:7999/sad/agreement-edge.git"
RepoEndpoint="${RepoEndpoint%.*}"
RepoEndpoint="${RepoEndpoint##*/}"
echo "$RepoEndpoint"
輸出:
agreement-edge
sed
版本,可以在文件上運行(如果要處理多行):
sed 's=.*/\(.*\).git$=\1=' file_name
或直接在字符串上:
sed 's=.*/\(.*\).git$=\1=' <<< 'ssh://git@stash.dev-company.net:7999/sad/agreement-edge.git'
…或帶有變量:
sed 's=.*/\(.*\).git$=\1=' <<< "$RepoEndPoint"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.