【问题标题】:Shell script to extract app name用于提取应用程序名称的 Shell 脚本
【发布时间】:2016-01-28 21:48:17
【问题描述】:

我在 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

我需要从中提取agreement-edge,agreement-middle,login-edge

假设 Repo url 设置为变量

RepoEndpoint=ssh://git@stash.dev-company.net:7999/sad/agreement-edge.git

如何从中提取协议边缘?

【问题讨论】:

  • 带 sed:echo "$RepoEndpoint" | sed 's|.*/||;s|\..*||'

标签: linux bash shell unix jenkins


【解决方案1】:

用 bash 的Parameter Expansion :

RepoEndpoint="ssh://git@stash.dev-company.net:7999/sad/agreement-edge.git"
RepoEndpoint="${RepoEndpoint%.*}"
RepoEndpoint="${RepoEndpoint##*/}"
echo "$RepoEndpoint"

输出:

协议边缘

【讨论】:

  • 我最终不需要.git
【解决方案2】:

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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 2011-01-09
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 2014-10-21
    • 2013-10-17
    相关资源
    最近更新 更多