【问题标题】:Linux replace remove chars from string and save to varLinux替换从字符串中删除字符并保存到var
【发布时间】:2017-05-10 08:03:55
【问题描述】:

这是我的 gitlab-ci.yml 文件。主要是它只是执行脚本行

    before_script:
  - export RELEASE=${CI_BUILD_REF_SLUG}

在 ${CI_BUILD_REF_SLUG} 中可以是 feature/myproduct-1

但我想删除“/”和“-”字符

我在一个简单的 linux 控制台中尝试过,如下所示:

echo "feature/myproduct-1" | tr -d /-

它奏效了。但我无法让它在 yml 中工作

所以我希望解析为 RELEASE 的值不含“-”和“/”字符。

更新:这是我想要的一半。现在我需要删除“/”,我完成了

RELEASE='feature/sendis-6'
new=$(echo $RELEASE | sed 's/-//g')
echo $new

【问题讨论】:

    标签: linux gitlab-ci


    【解决方案1】:

    我做到了

    before_script:
      - RELEASE=$(echo $CI_BUILD_REF_SLUG | sed "s/[^[[:alnum:]]//g")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-26
      • 2017-03-24
      • 2021-03-20
      • 2014-08-26
      • 1970-01-01
      • 1970-01-01
      • 2021-07-16
      • 1970-01-01
      相关资源
      最近更新 更多