#!/bin/bash #git fetch ssh://baidu.net@gerrit.baidu.net:29418/weixin refs/changes/72/16272/14 && git cherry-pick FETCH_HEAD#git fetch ssh://jenkins@gerrit.baidu.net:29418/weixin refs/changes/72/16272/14#git cherry-pick FETCH_HEAD -n#1.替换baidu.net#2.去掉&&后面的字符串#转移字符为 \CherryPick="git fetch ssh://baidu.net@gerrit.baidu.net:29418/weixin refs/changes/72/16272/14 && git cherry-pick FETCH_HEAD"echo "Orgin Str: [${CherryPick}]"substr=${CherryPick% &&*}echo "Substr: ${substr}"rep=$(echo $substr | sed 's/ssh:\/\/.*@gerrit/ssh:\/\/jenkins@gerrit/')echo "Replace Str: ${rep}"echo ">>>>>CherryPick Start<<<<"echo "Will exec : [${rep}]"echo ">>>>>CherryPick Start<<<<"#一句话command=$(echo ${CherryPick% &&*} | sed 's/ssh:\/\/.*@gerrit/ssh:\/\/jenkins@gerrit/')echo ">>>>>CherryPick Start command <<<<"echo "Will exec : [${command}]"echo ">>>>>CherryPick Start command<<<<"
参考
shell脚本之sed使用----替换、变量、转义字符 https://blog.csdn.net/wangcg123/article/details/50667883?utm_source=blogxgwz0
Linux Shell 截取字符串 https://www.cnblogs.com/fengbohello/p/5954895.html